﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ruoxian_novel
{
    public partial class AdminForm : Form
    {
        public AdminForm()
        {
            InitializeComponent();
        }

        private void AdminForm_Load(object sender, EventArgs e)
        {
            //窗体加载 公共模块
            this.Text = "若闲Ruoxian-Novel    " + Yonghu.name;
            Random random = new Random();
            int i = random.Next(3);
            switch (i)
            {
                case 0:
                    pictureBox_dingbu.Image = ruoxian_novel.Properties.Resources._4;
                    break;
                case 1:
                    pictureBox_dingbu.Image = ruoxian_novel.Properties.Resources._5;
                    break;
                case 2:
                    pictureBox_dingbu.Image = ruoxian_novel.Properties.Resources.星球1;
                    ruoxian.ForeColor = Color.White;
                    Ruoxian_Novel.ForeColor = Color.Cyan;
                    break;
            }
            ruoxian_ico.Parent = pictureBox_dingbu;
            ruoxian.Parent = pictureBox_dingbu;
            Ruoxian_Novel.Parent = pictureBox_dingbu;
            //初始页面 管理中心
            panel_guanlizhongxin_caidan.BringToFront();
            panel_guanlizhongxin.BringToFront();
            panel_shujiguanli.BringToFront();
            panel_guanlizhongxin_caidan.Enabled = true;
            panel_guanlizhongxin.Enabled = true;
            panel_gerenzhongxin_caidan.Enabled = false;
            panel_gerenzhongxin.Enabled = false;
            //管理中心 管理书籍 小说分类 下拉框绑定数据
            string sql = "select * from Fenlei";
            DataSet ds_fenlei = DBHelper.GetDataSet(sql);
            comboBox_shujiguanli_fenlei.DataSource = ds_fenlei.Tables[0];
            comboBox_shujiguanli_fenlei.ValueMember = "Fenlei";
            comboBox_shujiguanli_fenlei.DisplayMember = "Fenlei";
            //管理中心 管理书籍 小说状态 下拉框绑定数据
            sql = "select * from bookZhuangtai";
            DataSet ds_zhuangtai = DBHelper.GetDataSet(sql);
            comboBox_shujiguanli_zhuangtai.DataSource = ds_zhuangtai.Tables[0];
            comboBox_shujiguanli_zhuangtai.ValueMember = "bookZhuangtai";
            comboBox_shujiguanli_zhuangtai.DisplayMember = "bookZhuangtai";
            //管理中心 管理书籍 搜索结果 绑定数据
            sql = "select b.bookID,f.Fenlei bookFenlei,b.bookName,y.Name bookZuozhe,b.bookGengxin,z.bookZhuangtai bookZhuangtai,b.bookTime,b.bookJianjie,b.Fengjin from Books b,Fenlei f,Yonghu y,BookZhuangtai z where b.bookFenlei=f.FenleiID and b.bookZuozhe=y.Zhanghao and b.bookZhuangtai=z.bookZhuangtaiID";
            DataTable dt = DBHelper.GetDataTable(sql);
            DGV_shujiguanli_sousuo.DataSource = dt;
            DGV_shujiguanli_sousuo.Columns[0].Visible = false;
            DGV_shujiguanli_sousuo.Columns[6].Visible = false;
            DGV_shujiguanli_sousuo.Columns[7].Visible = false;
        }

        private void button_guanlizhongxin_Click(object sender, EventArgs e)
        {
            //管理中心
            panel_guanlizhongxin_caidan.BringToFront();
            panel_guanlizhongxin.BringToFront();
            panel_shujiguanli.BringToFront();
            panel_guanlizhongxin_caidan.Enabled = true;
            panel_guanlizhongxin.Enabled = true;
            panel_gerenzhongxin_caidan.Enabled = false;
            panel_gerenzhongxin.Enabled = false;
        }

        private void button_gerenzhongxin_Click(object sender, EventArgs e)
        {
            //我的主页
            label_wodezhuye_nicheng.Parent = pictureBox_wodezhuye_dingbu;
            label_wodezhuye_nicheng.Text = Yonghu.name;
            label_wodezhuye_uid.Text = "UID:" + Yonghu.zhanghao + " | E-mail:" + Yonghu.email;
            label_wodezhuye_gerenxinxi.Text = Yonghu.xingbie + " | " + Yonghu.shengri + " | " + Yonghu.diqu;
            richTextBox_wodezhuye_jianjie.Text = Yonghu.jianjie;
            panel_wodezhuye.BringToFront();
            //个人中心
            panel_gerenzhongxin_caidan.BringToFront();
            panel_gerenzhongxin.BringToFront();
            panel_gerenzhongxin_caidan.Enabled = true;
            panel_gerenzhongxin.Enabled = true;
            panel_guanlizhongxin_caidan.Enabled = false;
            panel_guanlizhongxin.Enabled = false;
        }

        private void button_shujiguanli_Click(object sender, EventArgs e)
        {
            //管理中心 书籍管理
            panel_shujiguanli.BringToFront();
            panel_guanlizhongxin.BringToFront();
            //管理中心 书籍管理 作品分类 下拉框绑定数据
            string sql = "select * from Fenlei";
            DataSet ds_fenlei = DBHelper.GetDataSet(sql);
            comboBox_shujiguanli_fenlei.DataSource = ds_fenlei.Tables[0];
            comboBox_shujiguanli_fenlei.ValueMember = "Fenlei";
            comboBox_shujiguanli_fenlei.DisplayMember = "Fenlei";
            //管理中心 书籍管理 写作状态 下拉框绑定数据
            sql = "select * from bookZhuangtai";
            DataSet ds_zhuangtai = DBHelper.GetDataSet(sql);
            comboBox_shujiguanli_zhuangtai.DataSource = ds_zhuangtai.Tables[0];
            comboBox_shujiguanli_zhuangtai.ValueMember = "bookZhuangtai";
            comboBox_shujiguanli_zhuangtai.DisplayMember = "bookZhuangtai";
            //管理中心 书籍管理 搜索结果 刷新数据
            sql = "select b.bookID,f.Fenlei bookFenlei,b.bookName,y.Name bookZuozhe,b.bookGengxin,z.bookZhuangtai bookZhuangtai,b.bookTime,b.bookJianjie,b.Fengjin from Books b,Fenlei f,Yonghu y,BookZhuangtai z where b.bookFenlei=f.FenleiID and b.bookZuozhe=y.Zhanghao and b.bookZhuangtai=z.bookZhuangtaiID";
            DataTable dt = DBHelper.GetDataTable(sql);
            DGV_shujiguanli_sousuo.DataSource = dt;
        }

        private void button_zhanghaoguanli_Click(object sender, EventArgs e)
        {
            //管理中心 账号管理
            panel_zhanghaoguanli.BringToFront();
            panel_guanlizhongxin.BringToFront();
            string sql;
            //管理中心 账号管理 账号身份 下拉框绑定数据
            if (Yonghu.shenfen == "超管")
            {
                sql = "select * from YonghuShenfen where YonghuShenfen!='超管'";
            }
            else
            {
                sql = "select * from YonghuShenfen where YonghuShenfen!='超管' and YonghuShenfen!='管理员'";
            }
            DataSet ds = DBHelper.GetDataSet(sql);
            comboBox_zhanghaoguanli_shenfen.DataSource = ds.Tables[0];
            comboBox_zhanghaoguanli_shenfen.ValueMember = "YonghuShenfen";
            comboBox_zhanghaoguanli_shenfen.DisplayMember = "YonghuShenfen";
            //管理中心 账号管理 性别 下拉框绑定数据
            sql = "select * from Xingbie";
            ds = DBHelper.GetDataSet(sql);
            comboBox_zhanghaoguanli_xingbie.DataSource = ds.Tables[0];
            comboBox_zhanghaoguanli_xingbie.ValueMember = "Xingbie";
            comboBox_zhanghaoguanli_xingbie.DisplayMember = "Xingbie";
            //管理中心 账号管理 生日 年 下拉框绑定数据
            comboBox_zhanghaoguanli_shengri_nian.Items.Clear();
            comboBox_zhanghaoguanli_shengri_nian.Items.Add("—");
            for (int i = DateTime.Now.Year; i >= DateTime.Now.Year - 100; i--)
            {
                comboBox_zhanghaoguanli_shengri_nian.Items.Add(i);
            }
            comboBox_zhanghaoguanli_shengri_nian.SelectedIndex = 0;
            //管理中心 账号管理 生日 月 下拉框绑定数据
            comboBox_zhanghaoguanli_shengri_yue.SelectedIndex = 0;
            //管理中心 账号管理 地区 下拉框绑定数据
            sql = "select * from Diqu";
            ds = DBHelper.GetDataSet(sql);
            comboBox_zhanghaoguanli_diqu.DataSource = ds.Tables[0];
            comboBox_zhanghaoguanli_diqu.ValueMember = "Diqu";
            comboBox_zhanghaoguanli_diqu.DisplayMember = "Diqu";
            //管理中心 账号管理 搜索结果 刷新数据
            if (Yonghu.shenfen == "超管")
            {
                sql = "select y.Zhanghao,s.YonghuShenfen Shenfen,y.Name,x.Xingbie,y.Shengri,d.Diqu,y.Jianjie,y.Email,y.Fengjin from Yonghu y,YonghuShenfen s,Xingbie x,Diqu d where y.Shenfen=s.YonghuShenfenID and y.Xingbie=x.XingbieID and y.Diqu=d.DiquID and s.YonghuShenfen!='超管'";
            }
            else
            {
                sql = "select y.Zhanghao,s.YonghuShenfen Shenfen,y.Name,x.Xingbie,y.Shengri,d.Diqu,y.Jianjie,y.Email,y.Fengjin from Yonghu y,YonghuShenfen s,Xingbie x,Diqu d where y.Shenfen=s.YonghuShenfenID and y.Xingbie=x.XingbieID and y.Diqu=d.DiquID and s.YonghuShenfen!='超管' and s.YonghuShenfen!='管理员'";
            }
            DataTable dt = DBHelper.GetDataTable(sql);
            DGV_zhanghaoguanli_sousuo.DataSource = dt;
        }

        private void button_fankiuguanli_Click(object sender, EventArgs e)
        {
            //绑定数据
            string sql = "select f.ID,y.Name,f.Neirong,f.Time,f.Zhuangtai from Fankui f,Yonghu y where f.Zhanghao=y.Zhanghao";
            DataTable dt = DBHelper.GetDataTable(sql);
            dataGridView_fankuiguanli.DataSource = dt;
            dataGridView_fankuiguanli.Columns["ID"].Visible = false;
            //填入数据
            try
            {
                richTextBox_fankuiguanli.Text = dataGridView_fankuiguanli.SelectedRows[0].Cells["Neirong"].Value.ToString();
            }
            catch
            {
                richTextBox_fankuiguanli.Text = "还没有人发送反馈呢！";
            }
            //管理中心 反馈管理
            panel_fankuiguanli.BringToFront();
            panel_guanlizhongxin.BringToFront();
        }

        private void button_bianjigonggao_Click(object sender, EventArgs e)
        {
            //绑定数据
            string sql = "select g.ID,g.Biaoti,g.Neirong,y.Name,g.Time from Gonggao g,Yonghu y where g.Zhanghao=y.Zhanghao";
            DataTable dt = DBHelper.GetDataTable(sql);
            dataGridView_bianjigonggao_gonggao.DataSource = dt;
            dataGridView_bianjigonggao_gonggao.Columns["ID"].Visible = false;
            //填入数据
            try
            {
                richTextBox_bianjigonggao_neirong.Text = dataGridView_bianjigonggao_gonggao.Rows[0].Cells["Neirong"].Value.ToString();
            }
            catch
            {
                richTextBox_bianjigonggao_neirong.Text = "";
            }
            //管理中心 编辑公告
            panel_bianjigonggao.BringToFront();
            panel_guanlizhongxin.BringToFront();
        }

        private void button_shujiguanli_sousuo_Click(object sender, EventArgs e)
        {
            //管理中心 书籍管理 搜索按钮
            string fenlei = comboBox_shujiguanli_fenlei.Text;
            string zhuangtai = comboBox_shujiguanli_zhuangtai.Text;
            string sousuo = textBox_shujiguanli_sousuo.Text;
            if (comboBox_shujiguanli_fenlei.Text == "全部")
            {
                fenlei = "%";
            }
            if (comboBox_shujiguanli_zhuangtai.Text == "全部")
            {
                zhuangtai = "%";
            }
            if (textBox_shujiguanli_sousuo.Text == "")
            {
                sousuo = "%";
            }
            string sql = string.Format("select b.bookID,f.Fenlei bookFenlei,b.bookName,y.Name bookZuozhe,b.bookGengxin,z.bookZhuangtai bookZhuangtai,b.bookTime,b.bookJianjie,b.Fengjin from Books b,Fenlei f,Yonghu y,BookZhuangtai z where b.bookFenlei=f.FenleiID and b.bookZuozhe=y.Zhanghao and b.bookZhuangtai=z.bookZhuangtaiID and f.Fenlei like '{0}' and z.bookZhuangtai like '{1}' and (b.bookName like '%{2}%' or y.Name like '%{3}%')", fenlei, zhuangtai, sousuo, sousuo);
            DataTable dt = DBHelper.GetDataTable(sql);
            DGV_shujiguanli_sousuo.DataSource = dt;
        }

        private void 封禁ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                //管理中心 书籍管理 封禁书籍
                if (MessageBox.Show("确定要封禁该书籍吗？", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                {
                    return;
                }
                string sql = string.Format("update Books set Fengjin='封禁' where bookID={0}", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
                DBHelper.ExecuteNonQuery(sql);
                //管理中心 书籍管理 刷新
                string fenlei = comboBox_shujiguanli_fenlei.Text;
                string zhuangtai = comboBox_shujiguanli_zhuangtai.Text;
                string sousuo = textBox_shujiguanli_sousuo.Text;
                if (comboBox_shujiguanli_fenlei.Text == "全部")
                {
                    fenlei = "%";
                }
                if (comboBox_shujiguanli_zhuangtai.Text == "全部")
                {
                    zhuangtai = "%";
                }
                if (textBox_shujiguanli_sousuo.Text == "")
                {
                    sousuo = "%";
                }
                sql = string.Format("select b.bookID,f.Fenlei bookFenlei,b.bookName,y.Name bookZuozhe,b.bookGengxin,z.bookZhuangtai bookZhuangtai,b.bookTime,b.bookJianjie,b.Fengjin from Books b,Fenlei f,Yonghu y,BookZhuangtai z where b.bookFenlei=f.FenleiID and b.bookZuozhe=y.Zhanghao and b.bookZhuangtai=z.bookZhuangtaiID and f.Fenlei like '{0}' and z.bookZhuangtai like '{1}' and (b.bookName like '%{2}%' or y.Name like '%{3}%')", fenlei, zhuangtai, sousuo, sousuo);
                DataTable dt = DBHelper.GetDataTable(sql);
                DGV_shujiguanli_sousuo.DataSource = dt;
                MessageBox.Show("成功封禁书籍");
            }
            catch
            {
                //封禁书籍 出错处理
                MessageBox.Show("书籍操作出错，可能封禁失败！");
            }
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                //管理中心 书籍管理 删除书籍
                if (MessageBox.Show("确定要删除该书籍吗？", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                {
                    return;
                }
                string sql = string.Format("delete Zhangjie where bookID='{0}' delete Books where bookID='{0}'", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
                DBHelper.ExecuteNonQuery(sql);
                //管理中心 书籍管理 刷新
                string fenlei = comboBox_shujiguanli_fenlei.Text;
                string zhuangtai = comboBox_shujiguanli_zhuangtai.Text;
                string sousuo = textBox_shujiguanli_sousuo.Text;
                if (comboBox_shujiguanli_fenlei.Text == "全部")
                {
                    fenlei = "%";
                }
                if (comboBox_shujiguanli_zhuangtai.Text == "全部")
                {
                    zhuangtai = "%";
                }
                if (textBox_shujiguanli_sousuo.Text == "")
                {
                    sousuo = "%";
                }
                sql = string.Format("select b.bookID,f.Fenlei bookFenlei,b.bookName,y.Name bookZuozhe,b.bookGengxin,z.bookZhuangtai bookZhuangtai,b.bookTime,b.bookJianjie,b.Fengjin from Books b,Fenlei f,Yonghu y,BookZhuangtai z where b.bookFenlei=f.FenleiID and b.bookZuozhe=y.Zhanghao and b.bookZhuangtai=z.bookZhuangtaiID and f.Fenlei like '{0}' and z.bookZhuangtai like '{1}' and (b.bookName like '%{2}%' or y.Name like '%{3}%')", fenlei, zhuangtai, sousuo, sousuo);
                DataTable dt = DBHelper.GetDataTable(sql);
                DGV_shujiguanli_sousuo.DataSource = dt;
                MessageBox.Show("成功删除书籍");
            }
            catch
            {
                //删除书籍 出错处理
                MessageBox.Show("书籍操作出错，可能删除失败！");
            }
        }

        private void DGV_shujiguanli_sousuo_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                //书籍管理 右键操作 操作区域
                if (e.Button == MouseButtons.Right)
                {
                    if (e.RowIndex >= 0)
                    {
                        //右键操作 右键选定
                        DGV_shujiguanli_sousuo.ClearSelection();
                        DGV_shujiguanli_sousuo.Rows[e.RowIndex].Selected = true;
                        //右键操作 弹出菜单
                        contextMenuStrip_shujiguanli.Show(MousePosition.X, MousePosition.Y);
                    }
                }
            }
            catch
            {
                //右键操作 故障处理
                MessageBox.Show("右键操作出错，请检修！");
            }
        }

        private void button_zhanghaoguanli_sousuo_Click(object sender, EventArgs e)
        {
            //管理中心 账号管理 搜索按钮
            string shenfen = comboBox_zhanghaoguanli_shenfen.Text;
            string xingbie = comboBox_zhanghaoguanli_xingbie.Text;
            string shengri;
            string diqu = comboBox_zhanghaoguanli_diqu.Text;
            string sousuo = textBox_zhanghaoguanli_sousuo.Text;
            if (comboBox_zhanghaoguanli_shenfen.Text == "全部")
            {
                shenfen = "%";
            }
            if (comboBox_zhanghaoguanli_xingbie.Text == "全部")
            {
                xingbie = "%";
            }
            if (comboBox_zhanghaoguanli_shengri_nian.Text == "—")
            {
                shengri = "____";
            }
            else
            {
                shengri = comboBox_zhanghaoguanli_shengri_nian.Text;
            }
            if (comboBox_zhanghaoguanli_shengri_yue.Text == "—")
            {
                shengri += "-%";
            }
            else
            {
                shengri += "-" + comboBox_zhanghaoguanli_shengri_yue.Text;
            }
            if (comboBox_zhanghaoguanli_diqu.Text == "全部")
            {
                diqu = "%";
            }
            if (textBox_zhanghaoguanli_sousuo.Text == "")
            {
                sousuo = "%";
            }
            string sql;
            if (Yonghu.shenfen == "超管")
            {
                sql = string.Format("select y.Zhanghao,s.YonghuShenfen Shenfen,y.Name,x.Xingbie,y.Shengri,d.Diqu,y.Jianjie,y.Fengjin from Yonghu y,YonghuShenfen s,Xingbie x,Diqu d where y.Shenfen=s.YonghuShenfenID and y.Xingbie=x.XingbieID and y.Diqu=d.DiquID and y.Shenfen in (select YonghuShenfenID from YonghuShenfen where YonghuShenfen like '{0}') and y.Xingbie in (select XingbieID from Xingbie where Xingbie like '{1}') and convert(nvarchar,y.Shengri,120) like '{2}%' and y.Diqu in (select DiquID from Diqu where Diqu like '{3}') and y.Name like '%{4}%' and s.YonghuShenfen!='超管'", shenfen, xingbie, shengri, diqu, sousuo);
            }
            else
            {
                sql = string.Format("select y.Zhanghao,s.YonghuShenfen Shenfen,y.Name,x.Xingbie,y.Shengri,d.Diqu,y.Jianjie,y.Fengjin from Yonghu y,YonghuShenfen s,Xingbie x,Diqu d where y.Shenfen=s.YonghuShenfenID and y.Xingbie=x.XingbieID and y.Diqu=d.DiquID and y.Shenfen in (select YonghuShenfenID from YonghuShenfen where YonghuShenfen like '{0}') and y.Xingbie in (select XingbieID from Xingbie where Xingbie like '{1}') and convert(nvarchar,y.Shengri,120) like '{2}%' and y.Diqu in (select DiquID from Diqu where Diqu like '{3}') and y.Name like '%{4}%' and s.YonghuShenfen!='超管' and s.YonghuShenfen!='管理员'", shenfen, xingbie, shengri, diqu, sousuo);
            }
            DataTable dt = DBHelper.GetDataTable(sql);
            DGV_zhanghaoguanli_sousuo.DataSource = dt;
        }

        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //管理中心 书籍管理 修改书籍 写作状态 下拉框绑定数据
            string sql = "select * from bookZhuangtai where bookZhuangtaiID!='0'";
            DataSet ds_zhuangtai = DBHelper.GetDataSet(sql);
            comboBox_shujiguanli_xiugai_zhuangtai.DataSource = ds_zhuangtai.Tables[0];
            comboBox_shujiguanli_xiugai_zhuangtai.ValueMember = "bookZhuangtai";
            comboBox_shujiguanli_xiugai_zhuangtai.DisplayMember = "bookZhuangtai";
            //管理中心 书籍管理 修改书籍 作品分类 下拉框绑定数据
            sql = "select * from Fenlei where FenleiID!='0'";
            DataSet ds_fenlei = DBHelper.GetDataSet(sql);
            comboBox_shujiguanli_xiugai_fenlei.DataSource = ds_fenlei.Tables[0];
            comboBox_shujiguanli_xiugai_fenlei.ValueMember = "Fenlei";
            comboBox_shujiguanli_xiugai_fenlei.DisplayMember = "Fenlei";
            //管理中心 书籍管理 修改书籍 复制作者ID
            sql = string.Format("select bookZuozhe from Books where bookID='{0}'", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
            DataTable dt_zuozheID = DBHelper.GetDataTable(sql);
            textBox_shujiguanli_xiugai_zuozheID.Text = dt_zuozheID.Rows[0][0].ToString();
            //管理中心 书籍管理 修改书籍 复制数据
            textBox_shujiguanli_xiugai_shuming.Text = DGV_shujiguanli_sousuo.SelectedRows[0].Cells[2].Value.ToString();
            textBox_shujiguanli_xiugai_zuozhe.Text = DGV_shujiguanli_sousuo.SelectedRows[0].Cells[3].Value.ToString();
            textBox_shujiguanli_xiugai_chuangjianshijian.Text = DGV_shujiguanli_sousuo.SelectedRows[0].Cells[6].Value.ToString();
            textBox_shujiguanli_xiugai_gengxinshijian.Text = DGV_shujiguanli_sousuo.SelectedRows[0].Cells[4].Value.ToString();
            textBox_shujiguanli_xiugai_jianjie.Text = DGV_shujiguanli_sousuo.SelectedRows[0].Cells[7].Value.ToString();
            comboBox_shujiguanli_xiugai_zhuangtai.Text = DGV_shujiguanli_sousuo.SelectedRows[0].Cells[5].Value.ToString();
            comboBox_shujiguanli_xiugai_fenlei.Text = DGV_shujiguanli_sousuo.SelectedRows[0].Cells[1].Value.ToString();
            //管理中心 书籍管理 修改书籍 显示页面
            panel_zhanghaoguanli_xiugai.BringToFront();
        }

        private void button_zhanghaoguanli_xiugai_quxiao_Click(object sender, EventArgs e)
        {
            //管理中心 书籍管理 修改书籍 取消按钮
            panel_shujiguanli.BringToFront();
        }

        private void button_zhanghaoguanli_xiugai_baocun_Click(object sender, EventArgs e)
        {
            //管理中心 书籍管理 修改书籍 保存按钮 非空数据
            if (textBox_shujiguanli_xiugai_shuming.Text == "")
            {
                MessageBox.Show("请输入书名！");
                return;
            }
            else if (textBox_shujiguanli_xiugai_zuozheID.Text == "")
            {
                MessageBox.Show("请输入UID！");
                return;
            }
            else if (textBox_shujiguanli_xiugai_chuangjianshijian.Text == "")
            {
                MessageBox.Show("请输入创建日期！");
                return;
            }
            else if (textBox_shujiguanli_xiugai_gengxinshijian.Text == "")
            {
                MessageBox.Show("请输入更新日期！");
                return;
            }
            //管理中心 书籍管理 修改书籍 保存按钮 纠正数据
            string sql = string.Format("select count(*) from Yonghu where zhanghao='{0}'", textBox_shujiguanli_xiugai_zuozheID.Text);
            DataTable dt_zuozhe = DBHelper.GetDataTable(sql);
            if (dt_zuozhe.Rows[0][0].ToString() == "0")
            {
                MessageBox.Show("该作者不存在！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //管理中心 书籍管理 修改书籍 保存按钮 修改数据
            sql = string.Format("update Books set bookFenlei=(select FenleiID from Fenlei where Fenlei='{0}'),bookName='{1}',bookZuozhe='{2}',bookGengxin='{3}',bookZhuangtai=(select bookZhuangtaiID from BookZhuangtai where bookZhuangtai='{4}'),bookTime='{5}',bookJianjie='{6}' where bookID='{7}'", comboBox_shujiguanli_xiugai_fenlei.Text, textBox_shujiguanli_xiugai_shuming.Text, textBox_shujiguanli_xiugai_zuozheID.Text, textBox_shujiguanli_xiugai_gengxinshijian.Text, comboBox_shujiguanli_xiugai_zhuangtai.Text, textBox_shujiguanli_xiugai_chuangjianshijian.Text, textBox_shujiguanli_xiugai_jianjie.Text, DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
            DBHelper.ExecuteNonQuery(sql);
            //管理中心 书籍管理 修改书籍 保存按钮 刷新数据
            string fenlei = comboBox_shujiguanli_fenlei.Text;
            string zhuangtai = comboBox_shujiguanli_zhuangtai.Text;
            string sousuo = textBox_shujiguanli_sousuo.Text;
            if (comboBox_shujiguanli_fenlei.Text == "全部")
            {
                fenlei = "%";
            }
            if (comboBox_shujiguanli_zhuangtai.Text == "全部")
            {
                zhuangtai = "%";
            }
            if (textBox_shujiguanli_sousuo.Text == "")
            {
                sousuo = "%";
            }
            sql = string.Format("select b.bookID,f.Fenlei bookFenlei,b.bookName,y.Name bookZuozhe,b.bookGengxin,z.bookZhuangtai bookZhuangtai,b.bookTime,b.bookJianjie,b.Fengjin from Books b,Fenlei f,Yonghu y,BookZhuangtai z where b.bookFenlei=f.FenleiID and b.bookZuozhe=y.Zhanghao and b.bookZhuangtai=z.bookZhuangtaiID and f.Fenlei like '{0}' and z.bookZhuangtai like '{1}' and (b.bookName like '%{2}%' or y.Name like '%{3}%')", fenlei, zhuangtai, sousuo, sousuo);
            DataTable dt = DBHelper.GetDataTable(sql);
            DGV_shujiguanli_sousuo.DataSource = dt;
            //管理中心 书籍管理 修改书籍 保存按钮 返回
            panel_shujiguanli.BringToFront();
        }

        private void DGV_zhanghaoguanli_sousuo_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                //账号管理 右键操作 操作区域
                if (e.Button == MouseButtons.Right)
                {
                    if (e.RowIndex >= 0)
                    {
                        //右键操作 右键选定
                        DGV_zhanghaoguanli_sousuo.ClearSelection();
                        DGV_zhanghaoguanli_sousuo.Rows[e.RowIndex].Selected = true;
                        //右键操作 弹出菜单
                        contextMenuStrip_zhanghaoguanli.Show(MousePosition.X, MousePosition.Y);
                    }
                }
            }
            catch
            {
                //右键操作 故障处理
                MessageBox.Show("右键操作出错，请检修！");
            }
        }

        private void 查看ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //管理中心 书籍管理 书籍信息 复制数据
            label1_shujixinxi_shuming.Text = DGV_shujiguanli_sousuo.SelectedRows[0].Cells[2].Value.ToString();
            button_shujixinxi_xiezuozhuangtai.Text = DGV_shujiguanli_sousuo.SelectedRows[0].Cells[5].Value.ToString();
            button_shujixinxi_zuopinfenlei.Text = DGV_shujiguanli_sousuo.SelectedRows[0].Cells[1].Value.ToString();
            label_shujixinxi_gengxinshijian.Text = "更新于" + DGV_shujiguanli_sousuo.SelectedRows[0].Cells[4].Value.ToString();
            richTextBox_shujixinxi_jianjie.Text = DGV_shujiguanli_sousuo.SelectedRows[0].Cells[7].Value.ToString();
            try
            {
                linkLabel_shujixinxi_zhangjie.Enabled = true;
                string sql = string.Format("select top 1* from Zhangjie where bookID='{0}' order by zhangjieGengxin desc", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
                DataTable dt = DBHelper.GetDataTable(sql);
                linkLabel_shujixinxi_zhangjie.Text = dt.Rows[0][1].ToString() + "  " + dt.Rows[0][2].ToString();
                try
                {
                    label__shujixinxi_zhangjieneirong.Text = dt.Rows[0][3].ToString().Substring(0, 50).Replace("\n", " ").Replace("\r", " ") + "...";
                }
                catch
                {
                    label__shujixinxi_zhangjieneirong.Text = dt.Rows[0][3].ToString().Replace("\n", " ").Replace("\r", " ") + "...";
                }
            }
            catch
            {
                linkLabel_shujixinxi_zhangjie.Enabled = false;
                linkLabel_shujixinxi_zhangjie.Text = "此书还没有任何章节呢！";
                label__shujixinxi_zhangjieneirong.Text = "没有内容！";
            }
            //管理中心 书籍管理 书籍信息 显示页面
            panel_shujixinxi.BringToFront();
        }

        private void button_guanlizhongxin_MouseEnter(object sender, EventArgs e)
        {
            //管理中心按钮 鼠标悬停时颜色
            button_guanlizhongxin.ForeColor = Color.White;
        }

        private void button_guanlizhongxin_MouseLeave(object sender, EventArgs e)
        {
            //管理中心按钮 鼠标离开时颜色
            button_guanlizhongxin.ForeColor = Color.Black;
        }

        private void button_guanlizhongxin_MouseDown(object sender, MouseEventArgs e)
        {
            //管理中心按钮 鼠标单击时颜色
            button_guanlizhongxin.ForeColor = Color.Black;
        }

        private void button_guanlizhongxin_MouseUp(object sender, MouseEventArgs e)
        {
            //管理中心按钮 鼠标单击释放时颜色
            button_guanlizhongxin.ForeColor = Color.White;
        }

        private void button_gerenzhongxin_MouseEnter(object sender, EventArgs e)
        {
            //个人中心按钮 鼠标悬停时颜色
            button_gerenzhongxin.ForeColor = Color.White;
        }

        private void button_gerenzhongxin_MouseLeave(object sender, EventArgs e)
        {
            //个人中心按钮 鼠标离开时颜色
            button_gerenzhongxin.ForeColor = Color.Black;
        }

        private void button_gerenzhongxin_MouseDown(object sender, MouseEventArgs e)
        {
            //个人中心按钮 鼠标单击时颜色
            button_gerenzhongxin.ForeColor = Color.Black;
        }

        private void button_gerenzhongxin_MouseUp(object sender, MouseEventArgs e)
        {
            //个人中心按钮 鼠标单击释放时颜色
            button_gerenzhongxin.ForeColor = Color.White;
        }

        private void linkLabel_shujixinxi_mulu_MouseEnter(object sender, EventArgs e)
        {
            //管理中心 书籍管理 书籍信息 全部目录 鼠标悬停时颜色
            linkLabel_shujixinxi_mulu.Image = ruoxian_novel.Properties.Resources.list__00c0c0_;
            linkLabel_shujixinxi_mulu.LinkColor = Color.FromArgb(0, 192, 192);
        }

        private void linkLabel_shujixinxi_mulu_MouseLeave(object sender, EventArgs e)
        {
            //管理中心 书籍管理 书籍信息 全部目录 鼠标离开时颜色
            linkLabel_shujixinxi_mulu.Image = ruoxian_novel.Properties.Resources.list;
            linkLabel_shujixinxi_mulu.LinkColor = Color.Silver;
        }

        private void button_shujixinxi_jiarushujia_MouseEnter(object sender, EventArgs e)
        {
            //管理中心 书籍管理 书籍信息 加入书架 鼠标悬停时颜色
            button_shujixinxi_pinglun.ForeColor = Color.White;
            button_shujixinxi_pinglun.FlatAppearance.BorderColor = Color.Cyan;
        }

        private void button_shujixinxi_jiarushujia_MouseLeave(object sender, EventArgs e)
        {
            //管理中心 书籍管理 书籍信息 加入书架 鼠标离开时颜色
            button_shujixinxi_pinglun.ForeColor = Color.FromArgb(0, 192, 192);
            button_shujixinxi_pinglun.FlatAppearance.BorderColor = Color.FromArgb(0, 192, 192);
        }

        private void button_shujixinxi_jiarushujia_MouseDown(object sender, MouseEventArgs e)
        {
            //管理中心 书籍管理 书籍信息 加入书架 鼠标单击时颜色
            button_shujixinxi_pinglun.FlatAppearance.BorderColor = Color.FromArgb(0, 192, 192);
        }

        private void button_shujixinxi_jiarushujia_MouseUp(object sender, MouseEventArgs e)
        {
            //管理中心 书籍管理 书籍信息 加入书架 鼠标单击释放时颜色
            button_shujixinxi_pinglun.FlatAppearance.BorderColor = Color.Cyan;
        }
        
        private void linkLabel_shujixinxi_mulu_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //管理中心 书籍管理 书籍信息 全部目录
            Zhangjie.zhangjieFenye = 1;
            string sql = string.Format("select * from (select row_number() over (order by zhangjieID) as id,* from Zhangjie where bookID='{0}') zhangjietb where id between {1} and {2}", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString(), Zhangjie.zhangjieFenye, Zhangjie.zhangjieFenye + 49);
            DataTable dt = DBHelper.GetDataTable(sql);
            DGV_zhangjieguanli_sousuo1.DataSource = dt;
            DGV_zhangjieguanli_sousuo1.Columns[0].Visible = false;
            DGV_zhangjieguanli_sousuo1.Columns[1].Visible = false;
            DGV_zhangjieguanli_sousuo1.Columns[4].Visible = false;
            DGV_zhangjieguanli_sousuo1.Columns[5].Visible = false;
            sql = string.Format("select count(*) from Zhangjie where bookID='{0}'", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
            if (int.Parse(DBHelper.GetDataTable(sql).Rows[0][0].ToString()) % 100 == 0)
            {
                label_zhangjieguanli_gongjiye.Text = "/ " + Convert.ToString(int.Parse(DBHelper.GetDataTable(sql).Rows[0][0].ToString()) / 50);
            }
            else
            {
                label_zhangjieguanli_gongjiye.Text = "/ " + Convert.ToString(int.Parse(DBHelper.GetDataTable(sql).Rows[0][0].ToString()) / 50 + 1);
            }
            textBox_zhangjieguanli_jiye.Text = "1";
            //管理中心 书籍管理 书籍信息 全部目录 显示页面
            panel_zhangjieguanli.BringToFront();
        }

        private void DGV_zhangjieguanli_sousuo1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                //章节管理 右键操作 操作区域
                if (e.Button == MouseButtons.Right)
                {
                    if (e.RowIndex >= 0)
                    {
                        //右键操作 右键选定
                        DGV_zhangjieguanli_sousuo1.ClearSelection();
                        DGV_zhangjieguanli_sousuo1.Rows[e.RowIndex].Selected = true;
                        //右键操作 弹出菜单
                        contextMenuStrip_zhangjieguanli.Show(MousePosition.X, MousePosition.Y);
                    }
                }
            }
            catch
            {
                //右键操作 故障处理
                MessageBox.Show("右键操作出错，请检修！");
            }
        }

        private void 打开ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //管理中心 书籍管理 章节管理 复制数据
            string sql = string.Format("select zhangjie,zhangjieName,zhangjieNeirong from zhangjie where zhangjieID='{0}'", DGV_zhangjieguanli_sousuo1.SelectedRows[0].Cells[1].Value.ToString());
            DataTable dt = DBHelper.GetDataTable(sql);
            label_chakanzhangjie_zhangjieming.Text = dt.Rows[0][1].ToString();
            richTextBox_chakanzhangjie.Text = dt.Rows[0][2].ToString();
            //管理中心 书籍管理 章节管理 显示页面
            panel_chakanzhangjie.BringToFront();
        }

        private void button_zhangjieguanli_fanhui_Click(object sender, EventArgs e)
        {
            //管理中心 书籍管理 章节管理 返回按钮
            panel_zhangjieguanli.SendToBack();
        }

        private void 删除ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            try
            {
                //管理中心 账号管理 删除账号
                if (MessageBox.Show("确定要删除该账号吗？", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                {
                    return;
                }
                string sql = string.Format("delete Zhangjie where bookID in (select bookID from Books where bookZuozhe='{0}') delete Books where bookID in (select bookID from Books where bookZuozhe='{0}') delete Yonghu where Zhanghao='{0}'", DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
                DBHelper.ExecuteNonQuery(sql);
                //管理中心 账号管理 刷新
                string shenfen = comboBox_zhanghaoguanli_shenfen.Text;
                string xingbie = comboBox_zhanghaoguanli_xingbie.Text;
                string shengri = "";
                string diqu = comboBox_zhanghaoguanli_diqu.Text;
                string sousuo = textBox_zhanghaoguanli_sousuo.Text;
                if (comboBox_zhanghaoguanli_shenfen.Text == "全部")
                {
                    shenfen = "%";
                }
                if (comboBox_zhanghaoguanli_xingbie.Text == "全部")
                {
                    xingbie = "%";
                }
                if (comboBox_zhanghaoguanli_shengri_nian.Text == "—")
                {
                    shengri = "____";
                }
                else
                {
                    shengri = comboBox_zhanghaoguanli_shengri_nian.Text;
                }
                if (comboBox_zhanghaoguanli_shengri_yue.Text == "—")
                {
                    shengri += "-%";
                }
                else
                {
                    shengri += "-" + comboBox_zhanghaoguanli_shengri_yue.Text;
                }
                if (comboBox_zhanghaoguanli_diqu.Text == "全部")
                {
                    diqu = "%";
                }
                if (textBox_zhanghaoguanli_sousuo.Text == "")
                {
                    sousuo = "%";
                }
                if (Yonghu.shenfen == "超管")
                {
                    sql = string.Format("select y.Zhanghao,s.YonghuShenfen Shenfen,y.Name,x.Xingbie,y.Shengri,d.Diqu,y.Jianjie,y.Fengjin from Yonghu y,YonghuShenfen s,Xingbie x,Diqu d where y.Shenfen=s.YonghuShenfenID and y.Xingbie=x.XingbieID and y.Diqu=d.DiquID and y.Shenfen in (select YonghuShenfenID from YonghuShenfen where YonghuShenfen like '{0}') and y.Xingbie in (select XingbieID from Xingbie where Xingbie like '{1}') and convert(nvarchar,y.Shengri,120) like '{2}%' and y.Diqu in (select DiquID from Diqu where Diqu like '{3}') and y.Name like '%{4}%' and s.YonghuShenfen!='超管'", shenfen, xingbie, shengri, diqu, sousuo);
                }
                else
                {
                    sql = string.Format("select y.Zhanghao,s.YonghuShenfen Shenfen,y.Name,x.Xingbie,y.Shengri,d.Diqu,y.Jianjie,y.Fengjin from Yonghu y,YonghuShenfen s,Xingbie x,Diqu d where y.Shenfen=s.YonghuShenfenID and y.Xingbie=x.XingbieID and y.Diqu=d.DiquID and y.Shenfen in (select YonghuShenfenID from YonghuShenfen where YonghuShenfen like '{0}') and y.Xingbie in (select XingbieID from Xingbie where Xingbie like '{1}') and convert(nvarchar,y.Shengri,120) like '{2}%' and y.Diqu in (select DiquID from Diqu where Diqu like '{3}') and y.Name like '%{4}%' and s.YonghuShenfen!='超管' and s.YonghuShenfen!='管理员'", shenfen, xingbie, shengri, diqu, sousuo);
                }
                DataTable dt = DBHelper.GetDataTable(sql);
                DGV_zhanghaoguanli_sousuo.DataSource = dt;
                MessageBox.Show("成功删除账号");
            }
            catch
            {
                //删除账号 出错处理
                MessageBox.Show("账号操作出错，可能删除失败！");
            }
        }

        private void 封禁ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            try
            {
                //管理中心 账号管理 封禁账号
                if (MessageBox.Show("确定要封禁该账号吗？", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                {
                    return;
                }
                string sql = string.Format("update Zhangjie set Fengjin='封禁' where bookID in (select bookID from Books where bookZuozhe='{0}') update Books set Fengjin='封禁' where bookID in (select bookID from Books where bookZuozhe='{0}') update Yonghu set Fengjin='封禁' where Zhanghao='{0}'", DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
                DBHelper.ExecuteNonQuery(sql);
                //管理中心 账号管理 刷新
                string shenfen = comboBox_zhanghaoguanli_shenfen.Text;
                string xingbie = comboBox_zhanghaoguanli_xingbie.Text;
                string shengri = "";
                string diqu = comboBox_zhanghaoguanli_diqu.Text;
                string sousuo = textBox_zhanghaoguanli_sousuo.Text;
                if (comboBox_zhanghaoguanli_shenfen.Text == "全部")
                {
                    shenfen = "%";
                }
                if (comboBox_zhanghaoguanli_xingbie.Text == "全部")
                {
                    xingbie = "%";
                }
                if (comboBox_zhanghaoguanli_shengri_nian.Text == "—")
                {
                    shengri = "____";
                }
                else
                {
                    shengri = comboBox_zhanghaoguanli_shengri_nian.Text;
                }
                if (comboBox_zhanghaoguanli_shengri_yue.Text == "—")
                {
                    shengri += "-%";
                }
                else
                {
                    shengri += "-" + comboBox_zhanghaoguanli_shengri_yue.Text;
                }
                if (comboBox_zhanghaoguanli_diqu.Text == "全部")
                {
                    diqu = "%";
                }
                if (textBox_zhanghaoguanli_sousuo.Text == "")
                {
                    sousuo = "%";
                }
                if (Yonghu.shenfen == "超管")
                {
                    sql = string.Format("select y.Zhanghao,s.YonghuShenfen Shenfen,y.Name,x.Xingbie,y.Shengri,d.Diqu,y.Jianjie,y.Fengjin from Yonghu y,YonghuShenfen s,Xingbie x,Diqu d where y.Shenfen=s.YonghuShenfenID and y.Xingbie=x.XingbieID and y.Diqu=d.DiquID and y.Shenfen in (select YonghuShenfenID from YonghuShenfen where YonghuShenfen like '{0}') and y.Xingbie in (select XingbieID from Xingbie where Xingbie like '{1}') and convert(nvarchar,y.Shengri,120) like '{2}%' and y.Diqu in (select DiquID from Diqu where Diqu like '{3}') and y.Name like '%{4}%' and s.YonghuShenfen!='超管'", shenfen, xingbie, shengri, diqu, sousuo);
                }
                else
                {
                    sql = string.Format("select y.Zhanghao,s.YonghuShenfen Shenfen,y.Name,x.Xingbie,y.Shengri,d.Diqu,y.Jianjie,y.Fengjin from Yonghu y,YonghuShenfen s,Xingbie x,Diqu d where y.Shenfen=s.YonghuShenfenID and y.Xingbie=x.XingbieID and y.Diqu=d.DiquID and y.Shenfen in (select YonghuShenfenID from YonghuShenfen where YonghuShenfen like '{0}') and y.Xingbie in (select XingbieID from Xingbie where Xingbie like '{1}') and convert(nvarchar,y.Shengri,120) like '{2}%' and y.Diqu in (select DiquID from Diqu where Diqu like '{3}') and y.Name like '%{4}%' and s.YonghuShenfen!='超管' and s.YonghuShenfen!='管理员'", shenfen, xingbie, shengri, diqu, sousuo);
                }
                DataTable dt = DBHelper.GetDataTable(sql);
                DGV_zhanghaoguanli_sousuo.DataSource = dt;
                MessageBox.Show("成功封禁账号");
            }
            catch
            {
                //封禁账号 出错处理
                MessageBox.Show("账号操作出错，可能封禁失败！");
            }
        }

        private void button_shujixinxi_fanhui_Click(object sender, EventArgs e)
        {
            //书籍信息 返回
            panel_shujixinxi.SendToBack();
        }

        private void DGV_shujiguanli_sousuo_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //打开书籍信息页面
            label1_shujixinxi_shuming.Text = DGV_shujiguanli_sousuo.SelectedRows[0].Cells[2].Value.ToString();
            button_shujixinxi_xiezuozhuangtai.Text = DGV_shujiguanli_sousuo.SelectedRows[0].Cells[5].Value.ToString();
            button_shujixinxi_zuopinfenlei.Text = DGV_shujiguanli_sousuo.SelectedRows[0].Cells[1].Value.ToString();
            label_shujixinxi_gengxinshijian.Text = "更新于" + DGV_shujiguanli_sousuo.SelectedRows[0].Cells[4].Value.ToString();
            richTextBox_shujixinxi_jianjie.Text = DGV_shujiguanli_sousuo.SelectedRows[0].Cells[7].Value.ToString();
            try
            {
                linkLabel_shujixinxi_zhangjie.Enabled = true;
                string sql = string.Format("select top 1* from Zhangjie where bookID='{0}' order by zhangjieID desc", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
                DataTable dt = DBHelper.GetDataTable(sql);
                linkLabel_shujixinxi_zhangjie.Text = dt.Rows[0][1].ToString() + "  " + dt.Rows[0][2].ToString();
                try
                {
                    label__shujixinxi_zhangjieneirong.Text = dt.Rows[0][3].ToString().Substring(0, 50).Replace("\n", " ").Replace("\r", " ") + "...";
                }
                catch
                {
                    label__shujixinxi_zhangjieneirong.Text = dt.Rows[0][3].ToString().Replace("\n", " ").Replace("\r", " ") + "...";
                }
            }
            catch
            {
                linkLabel_shujixinxi_zhangjie.Enabled = false;
                linkLabel_shujixinxi_zhangjie.Text = "此书还没有任何章节呢！";
                label__shujixinxi_zhangjieneirong.Text = "没有内容！";
            }
            //显示页面
            panel_shujixinxi.BringToFront();
        }

        private void 修改ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //账号管理 右键修改 性别 下拉框绑定数据
            string sql = "select * from Xingbie where XingbieID!=0";
            DataSet ds = DBHelper.GetDataSet(sql);
            comboBox_xiugaizhanghao_xingbie.DataSource = ds.Tables[0];
            comboBox_xiugaizhanghao_xingbie.ValueMember = "Xingbie";
            comboBox_xiugaizhanghao_xingbie.DisplayMember = "Xingbie";
            //账号管理 右键修改 生日 年 下拉框绑定数据
            comboBox_xiugaizhanghao_shengri_nian.Items.Clear();
            for (int i = DateTime.Now.Year; i >= DateTime.Now.Year - 100; i--)
            {
                comboBox_xiugaizhanghao_shengri_nian.Items.Add(i);
            }
            //账号管理 右键修改 地区 下拉框绑定数据
            sql = "select * from Diqu where DiquID!=0";
            ds = DBHelper.GetDataSet(sql);
            comboBox_xiugaizhanghao_diqu.DataSource = ds.Tables[0];
            comboBox_xiugaizhanghao_diqu.ValueMember = "Diqu";
            comboBox_xiugaizhanghao_diqu.DisplayMember = "Diqu";
            //账号管理 右键修改 身份 下拉框绑定数据
            sql = "select * from YonghuShenfen where YonghuShenfenID in (1,2)";
            ds = DBHelper.GetDataSet(sql);
            comboBox_xiugaizhanghao_shenfen.DataSource = ds.Tables[0];
            comboBox_xiugaizhanghao_shenfen.ValueMember = "YonghuShenfen";
            comboBox_xiugaizhanghao_shenfen.DisplayMember = "YonghuShenfen";
            //账号管理 右键修改 状态 下拉框绑定数据
            sql = "select * from Fengjin";
            ds = DBHelper.GetDataSet(sql);
            comboBox_xiugaizhanghao_fengjin.DataSource = ds.Tables[0];
            comboBox_xiugaizhanghao_fengjin.ValueMember = "Fengjin";
            comboBox_xiugaizhanghao_fengjin.DisplayMember = "Fengjin";
            //账号管理 右键修改 填充信息
            textBox_xiugaizhanghao_zhanghao.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString();
            comboBox_xiugaizhanghao_shenfen.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[1].Value.ToString();
            textBox_xiugaizhanghao_name.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[2].Value.ToString();
            comboBox_xiugaizhanghao_xingbie.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[3].Value.ToString();
            string[] shengri = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[4].Value.ToString().Split('/');
            comboBox_xiugaizhanghao_shengri_nian.Text = shengri[0];
            comboBox_xiugaizhanghao_shengri_yue.Text = shengri[1];
            //账号管理 右键修改 生日 日 下拉框绑定数据
            comboBox_xiugaizhanghao_shengri_ri.Items.Clear();
            int ri;
            if (comboBox_xiugaizhanghao_shengri_yue.Text == "1" || comboBox_xiugaizhanghao_shengri_yue.Text == "3" || comboBox_xiugaizhanghao_shengri_yue.Text == "5" || comboBox_xiugaizhanghao_shengri_yue.Text == "7" || comboBox_xiugaizhanghao_shengri_yue.Text == "8" || comboBox_xiugaizhanghao_shengri_yue.Text == "10" || comboBox_xiugaizhanghao_shengri_yue.Text == "12")
            {
                ri = 31;
            }
            else if (comboBox_xiugaizhanghao_shengri_yue.Text == "4" || comboBox_xiugaizhanghao_shengri_yue.Text == "6" || comboBox_xiugaizhanghao_shengri_yue.Text == "9" || comboBox_xiugaizhanghao_shengri_yue.Text == "11")
            {
                ri = 30;
            }
            else
            {
                if ((int.Parse(comboBox_xiugaizhanghao_shengri_nian.Text) % 4 == 0 && int.Parse(comboBox_xiugaizhanghao_shengri_nian.Text) % 100 != 0) || (int.Parse(comboBox_xiugaizhanghao_shengri_nian.Text) % 400 == 0))
                {
                    ri = 29;
                }
                else
                {
                    ri = 28;
                }
            }
            for (int i = 1; i <= ri; i++)
            {
                comboBox_xiugaizhanghao_shengri_ri.Items.Add(i);
            }
            if (shengri[2].Substring(1, 1) == " ")
            {
                comboBox_xiugaizhanghao_shengri_ri.Text = shengri[2].Substring(0, 1);
            }
            else
            {
                comboBox_xiugaizhanghao_shengri_ri.Text = shengri[2].Substring(0, 2);
            }
            comboBox_xiugaizhanghao_diqu.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[5].Value.ToString();
            textBox_xiugaizhanghao_jianjie.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[6].Value.ToString();
            textBox_xiugaizhanghao_email.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[7].Value.ToString();
            comboBox_xiugaizhanghao_fengjin.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[8].Value.ToString();
            //显示修改账号页面
            panel_xiugaizhanghao.BringToFront();
        }

        private void button_xiugaizhanghao_quxiao_Click(object sender, EventArgs e)
        {
            //修改账号 取消
            panel_xiugaizhanghao.SendToBack();
        }

        private void button_xiugaizhanghao_baocun_Click(object sender, EventArgs e)
        {
            //修改账号 确定
            if (textBox_xiugaizhanghao_name.Text == "")
            {
                MessageBox.Show("昵称还未输入呢！");
                return;
            }
            else if (comboBox_xiugaizhanghao_xingbie.Text == "")
            {
                MessageBox.Show("性别还未选择呢！");
                return;
            }
            else if (comboBox_xiugaizhanghao_shengri_nian.Text == ""|| comboBox_xiugaizhanghao_shengri_yue.Text == ""|| comboBox_xiugaizhanghao_shengri_ri.Text == "")
            {
                MessageBox.Show("生日还未选择呢！");
                return;
            }
            else if (comboBox_xiugaizhanghao_diqu.Text == "")
            {
                MessageBox.Show("地区还未选择呢！");
                return;
            }
            else if (textBox_xiugaizhanghao_email.Text == "")
            {
                MessageBox.Show("E-mail还未输入呢！");
                return;
            }
            else if (comboBox_xiugaizhanghao_shenfen.Text == "")
            {
                MessageBox.Show("身份还未选择呢！");
                return;
            }
            else if (comboBox_xiugaizhanghao_fengjin.Text == "")
            {
                MessageBox.Show("状态还未选择呢！");
                return;
            }

            string sql = string.Format("update Yonghu set Shenfen=(select YonghuShenfenID from YonghuShenfen where YonghuShenfen='{0}'),Name='{1}',Xingbie=(select XingbieID from Xingbie where Xingbie='{2}'),Shengri='{3}',Diqu=(select DiquID from Diqu where Diqu='{4}'),Jianjie='{5}',Email='{6}',Fengjin='{7}' where Zhanghao='{8}'", comboBox_xiugaizhanghao_shenfen.Text, textBox_xiugaizhanghao_name.Text, comboBox_xiugaizhanghao_xingbie.Text, comboBox_xiugaizhanghao_shengri_nian.Text + "-" + comboBox_xiugaizhanghao_shengri_yue.Text + "-" + comboBox_xiugaizhanghao_shengri_ri.Text, comboBox_xiugaizhanghao_diqu.Text, textBox_xiugaizhanghao_jianjie.Text, textBox_xiugaizhanghao_email.Text, comboBox_xiugaizhanghao_fengjin.Text, textBox_xiugaizhanghao_zhanghao.Text);
            if (!DBHelper.ExecuteNonQuery(sql))
            {
                MessageBox.Show("修改账号失败！");
            }
            //账号管理 刷新
            string shenfen = comboBox_zhanghaoguanli_shenfen.Text;
            string xingbie = comboBox_zhanghaoguanli_xingbie.Text;
            string shengri;
            string diqu = comboBox_zhanghaoguanli_diqu.Text;
            string sousuo = textBox_zhanghaoguanli_sousuo.Text;
            if (comboBox_zhanghaoguanli_shenfen.Text == "全部")
            {
                shenfen = "%";
            }
            if (comboBox_zhanghaoguanli_xingbie.Text == "全部")
            {
                xingbie = "%";
            }
            if (comboBox_zhanghaoguanli_shengri_nian.Text == "—")
            {
                shengri = "____";
            }
            else
            {
                shengri = comboBox_zhanghaoguanli_shengri_nian.Text;
            }
            if (comboBox_zhanghaoguanli_shengri_yue.Text == "—")
            {
                shengri += "-%";
            }
            else
            {
                shengri += "-" + comboBox_zhanghaoguanli_shengri_yue.Text;
            }
            if (comboBox_zhanghaoguanli_diqu.Text == "全部")
            {
                diqu = "%";
            }
            if (textBox_zhanghaoguanli_sousuo.Text == "")
            {
                sousuo = "%";
            }
            if (Yonghu.shenfen == "超管")
            {
                sql = string.Format("select y.Zhanghao,s.YonghuShenfen Shenfen,y.Name,x.Xingbie,y.Shengri,d.Diqu,y.Jianjie,y.Fengjin from Yonghu y,YonghuShenfen s,Xingbie x,Diqu d where y.Shenfen=s.YonghuShenfenID and y.Xingbie=x.XingbieID and y.Diqu=d.DiquID and y.Shenfen in (select YonghuShenfenID from YonghuShenfen where YonghuShenfen like '{0}') and y.Xingbie in (select XingbieID from Xingbie where Xingbie like '{1}') and convert(nvarchar,y.Shengri,120) like '{2}%' and y.Diqu in (select DiquID from Diqu where Diqu like '{3}') and y.Name like '%{4}%' and s.YonghuShenfen!='超管'", shenfen, xingbie, shengri, diqu, sousuo);
            }
            else
            {
                sql = string.Format("select y.Zhanghao,s.YonghuShenfen Shenfen,y.Name,x.Xingbie,y.Shengri,d.Diqu,y.Jianjie,y.Fengjin from Yonghu y,YonghuShenfen s,Xingbie x,Diqu d where y.Shenfen=s.YonghuShenfenID and y.Xingbie=x.XingbieID and y.Diqu=d.DiquID and y.Shenfen in (select YonghuShenfenID from YonghuShenfen where YonghuShenfen like '{0}') and y.Xingbie in (select XingbieID from Xingbie where Xingbie like '{1}') and convert(nvarchar,y.Shengri,120) like '{2}%' and y.Diqu in (select DiquID from Diqu where Diqu like '{3}') and y.Name like '%{4}%' and s.YonghuShenfen!='超管' and s.YonghuShenfen!='管理员'", shenfen, xingbie, shengri, diqu, sousuo);
            }
            DataTable dt = DBHelper.GetDataTable(sql);
            DGV_zhanghaoguanli_sousuo.DataSource = dt;
            //修改账号 返回
            panel_xiugaizhanghao.SendToBack();
        }

        private void button_zhangjieguanli_shangyiye_Click(object sender, EventArgs e)
        {
            textBox_zhangjieguanli_jiye.Text = Convert.ToString(int.Parse(textBox_zhangjieguanli_jiye.Text) - 1);
            //章节管理 上一页
            if (int.Parse(textBox_zhangjieguanli_jiye.Text) < 1)
            {
                textBox_zhangjieguanli_jiye.Text = "1";
                return;
            }
            else
            {
                Zhangjie.zhangjieFenye -= 50;
                string sql = string.Format("select * from (select row_number() over (order by zhangjieID) as id,* from Zhangjie where bookID='{0}') zhangjietb where id between {1} and {2}", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString(), Zhangjie.zhangjieFenye, Zhangjie.zhangjieFenye + 49);
                DataTable dt = DBHelper.GetDataTable(sql);
                DGV_zhangjieguanli_sousuo1.DataSource = dt;
            }
        }

        private void button_zhangjieguanli_xiayiye_Click(object sender, EventArgs e)
        {
            //章节管理 下一页
            if (int.Parse(textBox_zhangjieguanli_jiye.Text) < int.Parse(label_zhangjieguanli_gongjiye.Text.Substring(1)))
            {
                textBox_zhangjieguanli_jiye.Text = Convert.ToString(int.Parse(textBox_zhangjieguanli_jiye.Text) + 1);
                Zhangjie.zhangjieFenye += 50;
                string sql = string.Format("select * from (select row_number() over (order by zhangjieID) as id,* from Zhangjie where bookID='{0}') zhangjietb where id between {1} and {2}", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString(), Zhangjie.zhangjieFenye, Zhangjie.zhangjieFenye + 49);
                DataTable dt = DBHelper.GetDataTable(sql);
                DGV_zhangjieguanli_sousuo1.DataSource = dt;
            }
        }

        private void DGV_zhangjieguanli_sousuo1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            richTextBox_zhangjieguanli_yulan.Text = DGV_zhangjieguanli_sousuo1.SelectedRows[0].Cells[4].Value.ToString();
        }

        private void DGV_zhangjieguanli_sousuo1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            //管理中心 书籍管理 章节管理 复制数据
            string sql = string.Format("select zhangjie,zhangjieName,zhangjieNeirong from zhangjie where zhangjieID='{0}'", DGV_zhangjieguanli_sousuo1.SelectedRows[0].Cells[1].Value.ToString());
            DataTable dt = DBHelper.GetDataTable(sql);
            label_chakanzhangjie_zhangjieming.Text = dt.Rows[0][1].ToString();
            richTextBox_chakanzhangjie.Text = dt.Rows[0][2].ToString();
            //richTextBox_chakanzhangjie.Text
            //管理中心 书籍管理 章节管理 显示页面
            panel_chakanzhangjie.BringToFront();
        }

        private void button_chakanzhangjie_mulu_Click(object sender, EventArgs e)
        {
            //管理中心 书籍管理 书籍信息 全部目录
            Zhangjie.zhangjieFenye = 1;
            string sql = string.Format("select * from (select row_number() over (order by zhangjieID) as id,* from Zhangjie where bookID='{0}') zhangjietb where id between {1} and {2}", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString(), Zhangjie.zhangjieFenye, Zhangjie.zhangjieFenye + 49);
            DataTable dt = DBHelper.GetDataTable(sql);
            DGV_zhangjieguanli_sousuo1.DataSource = dt;
            DGV_zhangjieguanli_sousuo1.Columns[0].Visible = false;
            DGV_zhangjieguanli_sousuo1.Columns[1].Visible = false;
            DGV_zhangjieguanli_sousuo1.Columns[4].Visible = false;
            DGV_zhangjieguanli_sousuo1.Columns[5].Visible = false;
            sql = string.Format("select count(*) from Zhangjie where bookID='{0}'", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
            if (int.Parse(DBHelper.GetDataTable(sql).Rows[0][0].ToString()) % 50 == 0)
            {
                label_zhangjieguanli_gongjiye.Text = "/ " + Convert.ToString(int.Parse(DBHelper.GetDataTable(sql).Rows[0][0].ToString()) / 50);
            }
            else
            {
                label_zhangjieguanli_gongjiye.Text = "/ " + Convert.ToString(int.Parse(DBHelper.GetDataTable(sql).Rows[0][0].ToString()) / 50 + 1);
            }
            textBox_zhangjieguanli_jiye.Text = "1";
            //查看章节 返回目录
            panel_zhangjieguanli.BringToFront();
            panel_guanlizhongxin.BringToFront();
        }

        private void button_chakanzhangjie_quanping_Click(object sender, EventArgs e)
        {
            //查看章节 全屏
            if (this.WindowState== FormWindowState.Normal)
            {
                if (button_chakanzhangjie_quanping.Text == "全屏")
                {
                    panel_chakanzhangjie.Top = 0;
                    panel_chakanzhangjie.Left = 0;
                    panel_chakanzhangjie.Width = 1264;
                    panel_chakanzhangjie.Height = 681;
                    button_chakanzhangjie_quanping.Text = "还原";
                }
                else
                {
                    panel_chakanzhangjie.Top = 92;
                    panel_chakanzhangjie.Left = 150;
                    panel_chakanzhangjie.Width = 1100;
                    panel_chakanzhangjie.Height = 577;
                    button_chakanzhangjie_quanping.Text = "全屏";
                }
            }
            else if(this.WindowState == FormWindowState.Maximized)
            {
                this.WindowState = FormWindowState.Normal;
                if (button_chakanzhangjie_quanping.Text == "全屏")
                {
                    panel_chakanzhangjie.Top = 0;
                    panel_chakanzhangjie.Left = 0;
                    panel_chakanzhangjie.Width = 1264;
                    panel_chakanzhangjie.Height = 681;
                    button_chakanzhangjie_quanping.Text = "还原";
                }
                else
                {
                    panel_chakanzhangjie.Top = 92;
                    panel_chakanzhangjie.Left = 150;
                    panel_chakanzhangjie.Width = 1100;
                    panel_chakanzhangjie.Height = 577;
                    button_chakanzhangjie_quanping.Text = "全屏";
                }
                this.WindowState = FormWindowState.Maximized;
            }
        }

        private void linkLabel_shujixinxi_zhangjie_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //阅读最新章节
            string sql = string.Format("select zhangjieID from Zhangjie where bookID='{0}'", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
            Zhangjie.zhangjieLiebiao = DBHelper.GetDataTable(sql);
            sql = string.Format("select count(*) from Zhangjie where bookID = '{0}'", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
            Zhangjie.zhangjieWeizhi = int.Parse(DBHelper.GetDataTable(sql).Rows[0][0].ToString());
            sql = string.Format("select top 1 zhangjie,zhangjieName,zhangjieNeirong from Zhangjie where bookID='{0}' order by zhangjieID desc", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
            DataTable dt = DBHelper.GetDataTable(sql);
            label_chakanzhangjie_zhangjieming.Text = dt.Rows[0][1].ToString();
            richTextBox_chakanzhangjie.Text = dt.Rows[0][2].ToString();
            //显示阅读页面
            panel_chakanzhangjie.BringToFront();
        }

        private void button_shujixinxi_yuedu_Click(object sender, EventArgs e)
        {
            //阅读章节
            string sql = string.Format("select zhangjieID from Zhangjie where bookID='{0}'", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
            Zhangjie.zhangjieLiebiao = DBHelper.GetDataTable(sql);
            Zhangjie.zhangjieWeizhi = 0;
            sql = string.Format("select zhangjie,zhangjieName,zhangjieNeirong from Zhangjie where bookID='{0}' order by zhangjieID", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
            DataTable dt = DBHelper.GetDataTable(sql);
            label_chakanzhangjie_zhangjieming.Text = dt.Rows[0][1].ToString();
            richTextBox_chakanzhangjie.Text = dt.Rows[0][2].ToString();
            //显示阅读页面
            panel_chakanzhangjie.BringToFront();
        }

        private void button_chakanzhangjie_xiayizhang_Click(object sender, EventArgs e)
        {
            //阅读 下一章
            Zhangjie.zhangjieWeizhi++;
            string sql = string.Format("select count(*) from Zhangjie where bookID = '{0}'", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
            if (Zhangjie.zhangjieWeizhi < int.Parse(DBHelper.GetDataTable(sql).Rows[0][0].ToString()))
            {
                sql = string.Format("select zhangjie,zhangjieName,zhangjieNeirong from Zhangjie where bookID='{0}' and zhangjieID='{1}'", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString(), Zhangjie.zhangjieLiebiao.Rows[(int)Zhangjie.zhangjieWeizhi][0].ToString());
                DataTable dt = DBHelper.GetDataTable(sql);
                label_chakanzhangjie_zhangjieming.Text = dt.Rows[0][1].ToString();
                richTextBox_chakanzhangjie.Text = dt.Rows[0][2].ToString();
            }
            else
            {
                Zhangjie.zhangjieWeizhi--;
            }
        }

        private void button_chakanzhangjie_shangyizhang_Click(object sender, EventArgs e)
        {
            //阅读 上一章
            Zhangjie.zhangjieWeizhi--;
            if (Zhangjie.zhangjieWeizhi >= 0)
            {
                string sql = string.Format("select zhangjie,zhangjieName,zhangjieNeirong from Zhangjie where bookID='{0}' and zhangjieID='{1}'", DGV_shujiguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString(), Zhangjie.zhangjieLiebiao.Rows[(int)Zhangjie.zhangjieWeizhi][0].ToString());
                DataTable dt = DBHelper.GetDataTable(sql);
                label_chakanzhangjie_zhangjieming.Text = dt.Rows[0][1].ToString();
                richTextBox_chakanzhangjie.Text = dt.Rows[0][2].ToString();
            }
            else
            {
                Zhangjie.zhangjieWeizhi++;
            }
        }

        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[1].Value.ToString() == "读者")
            {
                //账号信息 填充信息
                label_gerenxinxi_nicheng.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[2].Value.ToString();
                label_gerenxinxi_uid.Text = "UID:" + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString() + " | E-mail:" + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[7].Value.ToString();
                label_gerenxinxi.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[3].Value.ToString() + " | " + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[4].Value.ToString().Substring(0, DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[4].Value.ToString().IndexOf(' ')) + " | " + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[5].Value.ToString() + " | " + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[1].Value.ToString();
                richTextBox_gerenxinxi_jianjie.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[6].Value.ToString();
                //账号信息
                panel_zhanghaoguanli_shujiguanli_sousuo.Visible = false;
                DGV_zhanghaoguanli_shujiguanli_sousuo.Visible = false;
                panel_zhanghaoguanli_gerenxinxi.BringToFront();
            }
            else
            {
                //账号信息 填充信息
                label_gerenxinxi_nicheng.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[2].Value.ToString();
                label_gerenxinxi_uid.Text = "UID:" + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString() + " | E-mail:" + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[7].Value.ToString();
                label_gerenxinxi.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[3].Value.ToString() + " | " + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[4].Value.ToString().Substring(0, DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[4].Value.ToString().IndexOf(' ')) + " | " + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[5].Value.ToString() + " | " + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[1].Value.ToString();
                richTextBox_gerenxinxi_jianjie.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[6].Value.ToString();
                //账号信息 书籍管理
                panel_zhanghaoguanli_shujiguanli_sousuo.Visible = true;
                DGV_zhanghaoguanli_shujiguanli_sousuo.Visible = true;
                panel_zhanghaoguanli_gerenxinxi.BringToFront();
                //账号信息 书籍管理 作品分类 下拉框绑定数据
                string sql = "select * from Fenlei";
                DataSet ds_fenlei = DBHelper.GetDataSet(sql);
                comboBox_zhanghaoguanli_shujiguanli_fenlei.DataSource = ds_fenlei.Tables[0];
                comboBox_zhanghaoguanli_shujiguanli_fenlei.ValueMember = "Fenlei";
                comboBox_zhanghaoguanli_shujiguanli_fenlei.DisplayMember = "Fenlei";
                //账号信息 书籍管理 写作状态 下拉框绑定数据
                sql = "select * from bookZhuangtai";
                DataSet ds_zhuangtai = DBHelper.GetDataSet(sql);
                comboBox_zhanghaoguanli_shujiguanli_zhuangtai.DataSource = ds_zhuangtai.Tables[0];
                comboBox_zhanghaoguanli_shujiguanli_zhuangtai.ValueMember = "bookZhuangtai";
                comboBox_zhanghaoguanli_shujiguanli_zhuangtai.DisplayMember = "bookZhuangtai";
                //账号信息 书籍管理 搜索结果 刷新数据
                sql = string.Format("select b.bookID,f.Fenlei bookFenlei,b.bookName,y.Name bookZuozhe,b.bookGengxin,z.bookZhuangtai bookZhuangtai,b.bookTime,b.bookJianjie,b.Fengjin from Books b,Fenlei f,Yonghu y,BookZhuangtai z where b.bookFenlei=f.FenleiID and b.bookZuozhe=y.Zhanghao and b.bookZhuangtai=z.bookZhuangtaiID and Zhanghao='{0}'", DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
                DataTable dt = DBHelper.GetDataTable(sql);
                DGV_zhanghaoguanli_shujiguanli_sousuo.DataSource = dt;
                DGV_zhanghaoguanli_shujiguanli_sousuo.Columns[0].Visible = false;
                DGV_zhanghaoguanli_shujiguanli_sousuo.Columns[6].Visible = false;
                DGV_zhanghaoguanli_shujiguanli_sousuo.Columns[7].Visible = false;
            }
        }

        private void button_zhanghaoguanli_shujiguanli_sousuo_Click(object sender, EventArgs e)
        {
            //管理中心 书籍管理 搜索按钮
            string fenlei = comboBox_zhanghaoguanli_shujiguanli_fenlei.Text;
            string zhuangtai = comboBox_zhanghaoguanli_shujiguanli_zhuangtai.Text;
            string sousuo = textBox_zhanghaoguanli_shujiguanli_sousuo.Text;
            if (comboBox_zhanghaoguanli_shujiguanli_fenlei.Text == "全部")
            {
                fenlei = "%";
            }
            if (comboBox_zhanghaoguanli_shujiguanli_zhuangtai.Text == "全部")
            {
                zhuangtai = "%";
            }
            if (textBox_zhanghaoguanli_shujiguanli_sousuo.Text == "")
            {
                sousuo = "%";
            }
            string sql = string.Format("select b.bookID,f.Fenlei bookFenlei,b.bookName,y.Name bookZuozhe,b.bookGengxin,z.bookZhuangtai bookZhuangtai,b.bookTime,b.bookJianjie,b.Fengjin from Books b,Fenlei f,Yonghu y,BookZhuangtai z where b.bookFenlei=f.FenleiID and b.bookZuozhe=y.Zhanghao and b.bookZhuangtai=z.bookZhuangtaiID and f.Fenlei like '{0}' and z.bookZhuangtai like '{1}' and (b.bookName like '%{2}%' or y.Name like '%{3}%')", fenlei, zhuangtai, sousuo, sousuo);
            DataTable dt = DBHelper.GetDataTable(sql);
            DGV_zhanghaoguanli_shujiguanli_sousuo.DataSource = dt;
        }

        private void comboBox_xiugaizhanghao_shengri_nian_SelectedIndexChanged(object sender, EventArgs e)
        {
            //修改账号 生日 日 下拉框绑定数据
            comboBox_xiugaizhanghao_shengri_ri.Items.Clear();
            int ri;
            if (comboBox_xiugaizhanghao_shengri_yue.Text == "1" || comboBox_xiugaizhanghao_shengri_yue.Text == "3" || comboBox_xiugaizhanghao_shengri_yue.Text == "5" || comboBox_xiugaizhanghao_shengri_yue.Text == "7" || comboBox_xiugaizhanghao_shengri_yue.Text == "8" || comboBox_xiugaizhanghao_shengri_yue.Text == "10" || comboBox_xiugaizhanghao_shengri_yue.Text == "12")
            {
                ri = 31;
            }
            else if (comboBox_xiugaizhanghao_shengri_yue.Text == "4" || comboBox_xiugaizhanghao_shengri_yue.Text == "6" || comboBox_xiugaizhanghao_shengri_yue.Text == "9" || comboBox_xiugaizhanghao_shengri_yue.Text == "11")
            {
                ri = 30;
            }
            else
            {
                if ((int.Parse(comboBox_xiugaizhanghao_shengri_nian.Text) % 4 == 0 && int.Parse(comboBox_xiugaizhanghao_shengri_nian.Text) % 100 != 0) || (int.Parse(comboBox_xiugaizhanghao_shengri_nian.Text) % 400 == 0))
                {
                    ri = 29;
                }
                else
                {
                    ri = 28;
                }
            }
            for (int i = 1; i <= ri; i++)
            {
                comboBox_xiugaizhanghao_shengri_ri.Items.Add(i);
            }
        }

        private void comboBox_xiugaizhanghao_shengri_yue_SelectedIndexChanged(object sender, EventArgs e)
        {
            //修改账号 生日 日 下拉框绑定数据
            comboBox_xiugaizhanghao_shengri_ri.Items.Clear();
            int ri;
            if (comboBox_xiugaizhanghao_shengri_yue.Text == "1" || comboBox_xiugaizhanghao_shengri_yue.Text == "3" || comboBox_xiugaizhanghao_shengri_yue.Text == "5" || comboBox_xiugaizhanghao_shengri_yue.Text == "7" || comboBox_xiugaizhanghao_shengri_yue.Text == "8" || comboBox_xiugaizhanghao_shengri_yue.Text == "10" || comboBox_xiugaizhanghao_shengri_yue.Text == "12")
            {
                ri = 31;
            }
            else if (comboBox_xiugaizhanghao_shengri_yue.Text == "4" || comboBox_xiugaizhanghao_shengri_yue.Text == "6" || comboBox_xiugaizhanghao_shengri_yue.Text == "9" || comboBox_xiugaizhanghao_shengri_yue.Text == "11")
            {
                ri = 30;
            }
            else
            {
                if ((int.Parse(comboBox_xiugaizhanghao_shengri_nian.Text) % 4 == 0 && int.Parse(comboBox_xiugaizhanghao_shengri_nian.Text) % 100 != 0) || (int.Parse(comboBox_xiugaizhanghao_shengri_nian.Text) % 400 == 0))
                {
                    ri = 29;
                }
                else
                {
                    ri = 28;
                }
            }
            for (int i = 1; i <= ri; i++)
            {
                comboBox_xiugaizhanghao_shengri_ri.Items.Add(i);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //个人信息 返回账号管理
            panel_zhanghaoguanli.BringToFront();
        }

        private void pictureBox_gerenxinxi_touxiang_Click(object sender, EventArgs e)
        {

        }

        private void button_wodezhuye_Click(object sender, EventArgs e)
        {
            //我的主页
            label_wodezhuye_nicheng.Text = Yonghu.name;
            label_wodezhuye_uid.Text = "UID:" + Yonghu.zhanghao + " | E-mail:" + Yonghu.email;
            label_wodezhuye_gerenxinxi.Text = Yonghu.xingbie + " | " + Yonghu.shengri + " | " + Yonghu.diqu;
            richTextBox_wodezhuye_jianjie.Text = Yonghu.jianjie;
            panel_wodezhuye.BringToFront();
        }

        private void DGV_zhanghaoguanli_sousuo_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[1].Value.ToString() == "读者")
            {
                //账号信息 填充信息
                label_gerenxinxi_nicheng.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[2].Value.ToString();
                label_gerenxinxi_uid.Text = "UID:" + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString() + " | E-mail:" + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[7].Value.ToString();
                label_gerenxinxi.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[3].Value.ToString() + " | " + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[4].Value.ToString().Substring(0, DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[4].Value.ToString().IndexOf(' ')) + " | " + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[5].Value.ToString() + " | " + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[1].Value.ToString();
                richTextBox_gerenxinxi_jianjie.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[6].Value.ToString();
                //账号信息
                panel_zhanghaoguanli_shujiguanli_sousuo.Visible = false;
                DGV_zhanghaoguanli_shujiguanli_sousuo.Visible = false;
                panel_zhanghaoguanli_gerenxinxi.BringToFront();
            }
            else
            {
                //账号信息 填充信息
                label_gerenxinxi_nicheng.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[2].Value.ToString();
                label_gerenxinxi_uid.Text = "UID:" + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString() + " | E-mail:" + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[7].Value.ToString();
                label_gerenxinxi.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[3].Value.ToString() + " | " + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[4].Value.ToString().Substring(0, DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[4].Value.ToString().IndexOf(' ')) + " | " + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[5].Value.ToString() + " | " + DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[1].Value.ToString();
                richTextBox_gerenxinxi_jianjie.Text = DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[6].Value.ToString();
                //账号信息 书籍管理
                panel_zhanghaoguanli_shujiguanli_sousuo.Visible = true;
                DGV_zhanghaoguanli_shujiguanli_sousuo.Visible = true;
                panel_zhanghaoguanli_gerenxinxi.BringToFront();
                //账号信息 书籍管理 作品分类 下拉框绑定数据
                string sql = "select * from Fenlei";
                DataSet ds_fenlei = DBHelper.GetDataSet(sql);
                comboBox_zhanghaoguanli_shujiguanli_fenlei.DataSource = ds_fenlei.Tables[0];
                comboBox_zhanghaoguanli_shujiguanli_fenlei.ValueMember = "Fenlei";
                comboBox_zhanghaoguanli_shujiguanli_fenlei.DisplayMember = "Fenlei";
                //账号信息 书籍管理 写作状态 下拉框绑定数据
                sql = "select * from bookZhuangtai";
                DataSet ds_zhuangtai = DBHelper.GetDataSet(sql);
                comboBox_zhanghaoguanli_shujiguanli_zhuangtai.DataSource = ds_zhuangtai.Tables[0];
                comboBox_zhanghaoguanli_shujiguanli_zhuangtai.ValueMember = "bookZhuangtai";
                comboBox_zhanghaoguanli_shujiguanli_zhuangtai.DisplayMember = "bookZhuangtai";
                //账号信息 书籍管理 搜索结果 刷新数据
                sql = string.Format("select b.bookID,f.Fenlei bookFenlei,b.bookName,y.Name bookZuozhe,b.bookGengxin,z.bookZhuangtai bookZhuangtai,b.bookTime,b.bookJianjie,b.Fengjin from Books b,Fenlei f,Yonghu y,BookZhuangtai z where b.bookFenlei=f.FenleiID and b.bookZuozhe=y.Zhanghao and b.bookZhuangtai=z.bookZhuangtaiID and Zhanghao='{0}'", DGV_zhanghaoguanli_sousuo.SelectedRows[0].Cells[0].Value.ToString());
                DataTable dt = DBHelper.GetDataTable(sql);
                DGV_zhanghaoguanli_shujiguanli_sousuo.DataSource = dt;
                DGV_zhanghaoguanli_shujiguanli_sousuo.Columns[0].Visible = false;
                DGV_zhanghaoguanli_shujiguanli_sousuo.Columns[6].Visible = false;
                DGV_zhanghaoguanli_shujiguanli_sousuo.Columns[7].Visible = false;
            }
        }

        private void button_bianjigonggao_shuaxin_Click(object sender, EventArgs e)
        {
            //编辑公告 刷新
            string sql = "select g.ID,g.Biaoti,g.Neirong,y.Name,g.Time from Gonggao g,Yonghu y where g.Zhanghao=y.Zhanghao";
            DataTable dt = DBHelper.GetDataTable(sql);
            //填充数据
            dataGridView_bianjigonggao_gonggao.DataSource = dt;
            try
            {
                richTextBox_bianjigonggao_neirong.Text = dataGridView_bianjigonggao_gonggao.Rows[0].Cells["Neirong"].Value.ToString();
            }
            catch
            {
                richTextBox_bianjigonggao_neirong.Text = "";
            }
        }

        private void dataGridView_bianjigonggao_gonggao_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //填充数据
            try
            {
                richTextBox_bianjigonggao_neirong.Text = dataGridView_bianjigonggao_gonggao.Rows[0].Cells["Neirong"].Value.ToString();
            }
            catch
            {
                richTextBox_bianjigonggao_neirong.Text = "";
            }
        }

        private void button_bianjigonggao_xinjian_Click(object sender, EventArgs e)
        {
            //清空数据
            textBox_bianjigonggao_xinjian_biaoti.Text = "";
            richTextBox_bianjigonggao_xinjian_neirong.Text = "";
            //新建
            button_bianjigonggao_xinjian_baocun.Text = "保存";
            panel_bianjigonggao_xinjian.BringToFront();
        }

        private void button_bianjigonggao_xinjian_fanhui_Click(object sender, EventArgs e)
        {
            //返回
            panel_bianjigonggao_xinjian.SendToBack();
            //清空数据
            textBox_bianjigonggao_xinjian_biaoti.Text = "";
            richTextBox_bianjigonggao_xinjian_neirong.Text = "";
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            //保存
            if (button_bianjigonggao_xinjian_baocun.Text == "保存")
            {
                string sqlStr = string.Format("insert Gonggao (Zhanghao,Biaoti,Neirong) select '{0}','{1}','{2}'", Yonghu.zhanghao, textBox_bianjigonggao_xinjian_biaoti.Text, richTextBox_bianjigonggao_xinjian_neirong.Text);
                DBHelper.ExecuteNonQuery(sqlStr);
            }
            else if (button_bianjigonggao_xinjian_baocun.Text == "修改")
            {
                string sqlStr = string.Format("update Gonggao set Biaoti='{0}',Neirong='{1}' where ID='{2}'", textBox_bianjigonggao_xinjian_biaoti.Text, richTextBox_bianjigonggao_xinjian_neirong.Text, dataGridView_bianjigonggao_gonggao.SelectedRows[0].Cells["ID"].Value.ToString());
                DBHelper.ExecuteNonQuery(sqlStr);
            }
            //返回
            MessageBox.Show("保存成功！");
            panel_bianjigonggao_xinjian.SendToBack();
            //清空数据
            textBox_bianjigonggao_xinjian_biaoti.Text = "";
            richTextBox_bianjigonggao_xinjian_neirong.Text = "";
            //编辑公告 刷新
            string sql = "select g.ID,g.Biaoti,g.Neirong,y.Name,g.Time from Gonggao g,Yonghu y where g.Zhanghao=y.Zhanghao";
            DataTable dt = DBHelper.GetDataTable(sql);
            //填充数据
            dataGridView_bianjigonggao_gonggao.DataSource = dt;
            try
            {
                richTextBox_bianjigonggao_neirong.Text = dataGridView_bianjigonggao_gonggao.Rows[0].Cells["Neirong"].Value.ToString();
            }
            catch
            {
                richTextBox_bianjigonggao_neirong.Text = "";
            }
        }

        private void dataGridView_bianjigonggao_gonggao_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //填入数据
            textBox_bianjigonggao_xinjian_biaoti.Text = dataGridView_bianjigonggao_gonggao.SelectedRows[0].Cells["Biaoti"].Value.ToString();
            richTextBox_bianjigonggao_xinjian_neirong.Text = dataGridView_bianjigonggao_gonggao.SelectedRows[0].Cells["Neirong"].Value.ToString();
            //编辑
            button_bianjigonggao_xinjian_baocun.Text = "修改";
            panel_bianjigonggao_xinjian.BringToFront();
        }

        private void dataGridView_bianjigonggao_gonggao_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                //公告管理 右键操作 操作区域
                if (e.Button == MouseButtons.Right)
                {
                    if (e.RowIndex >= 0)
                    {
                        //右键操作 右键选定
                        dataGridView_bianjigonggao_gonggao.ClearSelection();
                        dataGridView_bianjigonggao_gonggao.Rows[e.RowIndex].Selected = true;
                        //右键操作 弹出菜单
                        contextMenuStrip_bianjigonggao.Show(MousePosition.X, MousePosition.Y);
                    }
                }
            }
            catch
            {
                //右键操作 故障处理
                MessageBox.Show("右键操作出错，请检修！");
            }
        }

        private void 编辑ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //填入数据
            textBox_bianjigonggao_xinjian_biaoti.Text = dataGridView_bianjigonggao_gonggao.SelectedRows[0].Cells["Biaoti"].Value.ToString();
            richTextBox_bianjigonggao_xinjian_neirong.Text = dataGridView_bianjigonggao_gonggao.SelectedRows[0].Cells["Neirong"].Value.ToString();
            //编辑
            button_bianjigonggao_xinjian_baocun.Text = "修改";
            panel_bianjigonggao_xinjian.BringToFront();
        }

        private void 删除ToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            //删除公告
            if(MessageBox.Show("您确定要删除吗？","",MessageBoxButtons.YesNo,MessageBoxIcon.Information) == DialogResult.Yes)
            {
                string sql = string.Format("delete Gonggao where ID='{0}'", dataGridView_bianjigonggao_gonggao.SelectedRows[0].Cells["ID"].Value.ToString());
                DBHelper.ExecuteNonQuery(sql);
                MessageBox.Show("删除成功！");
                //编辑公告 刷新
                sql = "select g.ID,g.Biaoti,g.Neirong,y.Name,g.Time from Gonggao g,Yonghu y where g.Zhanghao=y.Zhanghao";
                DataTable dt = DBHelper.GetDataTable(sql);
                //填充数据
                dataGridView_bianjigonggao_gonggao.DataSource = dt;
                try
                {
                    richTextBox_bianjigonggao_neirong.Text = dataGridView_bianjigonggao_gonggao.Rows[0].Cells["Neirong"].Value.ToString();
                }
                catch
                {
                    richTextBox_bianjigonggao_neirong.Text = "";
                }
            }
        }

        private void button_fankuiguanli_chuli_Click(object sender, EventArgs e)
        {
            //处理反馈
            string sql = string.Format("update Fankui set Zhuangtai='{0}' where ID='{1}'", "已处理", dataGridView_fankuiguanli.SelectedRows[0].Cells["ID"].Value.ToString());
            DBHelper.ExecuteNonQuery(sql);
            //刷新数据
            sql = "select f.ID,y.Name,f.Neirong,f.Time,f.Zhuangtai from Fankui f,Yonghu y where f.Zhanghao=y.Zhanghao";
            DataTable dt = DBHelper.GetDataTable(sql);
            dataGridView_fankuiguanli.DataSource = dt;
            //填入数据
            try
            {
                richTextBox_fankuiguanli.Text = dataGridView_fankuiguanli.SelectedRows[0].Cells["Neirong"].Value.ToString();
            }
            catch
            {
                richTextBox_fankuiguanli.Text = "还没有人发送反馈呢！";
            }
        }

        private void button_fankuiguanli_shuaxin_Click(object sender, EventArgs e)
        {
            //刷新数据
            string sql = "select f.ID,y.Name,f.Neirong,f.Time,f.Zhuangtai from Fankui f,Yonghu y where f.Zhanghao=y.Zhanghao";
            DataTable dt = DBHelper.GetDataTable(sql);
            dataGridView_fankuiguanli.DataSource = dt;
            //填入数据
            try
            {
                richTextBox_fankuiguanli.Text = dataGridView_fankuiguanli.SelectedRows[0].Cells["Neirong"].Value.ToString();
            }
            catch
            {
                richTextBox_fankuiguanli.Text = "还没有人发送反馈呢！";
            }
        }

        private void dataGridView_fankuiguanli_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //填入数据
            try
            {
                richTextBox_fankuiguanli.Text = dataGridView_fankuiguanli.SelectedRows[0].Cells["Neirong"].Value.ToString();
            }
            catch
            {
                richTextBox_fankuiguanli.Text = "还没有人发送反馈呢！";
            }
        }

        private void button_wodezhuye_xiugai_Click(object sender, EventArgs e)
        {
            //个人信息 性别 下拉框绑定数据
            string sql = "select * from Xingbie where XingbieID!=0";
            DataSet ds = DBHelper.GetDataSet(sql);
            comboBox_gerenxinxi_xingbie.DataSource = ds.Tables[0];
            comboBox_gerenxinxi_xingbie.ValueMember = "Xingbie";
            comboBox_gerenxinxi_xingbie.DisplayMember = "Xingbie";
            comboBox_gerenxinxi_xingbie.SelectedIndex = -1;
            //个人信息 地区 下拉框绑定数据
            sql = "select * from Diqu where DiquID!=0";
            ds = DBHelper.GetDataSet(sql);
            comboBox_gerenxinxi_diqu.DataSource = ds.Tables[0];
            comboBox_gerenxinxi_diqu.ValueMember = "Diqu";
            comboBox_gerenxinxi_diqu.DisplayMember = "Diqu";
            comboBox_gerenxinxi_diqu.SelectedIndex = -1;
            //个人信息 生日 年 下拉框绑定数据
            comboBox_gerenxinxi_shengri_nian.Items.Clear();
            for (int i = DateTime.Now.Year; i >= DateTime.Now.Year - 100; i--)
            {
                comboBox_gerenxinxi_shengri_nian.Items.Add(i);
            }
            //填入信息
            textBox_gerenxinxi_name.Text = Yonghu.name;
            comboBox_gerenxinxi_xingbie.Text = Yonghu.xingbie;
            comboBox_gerenxinxi_diqu.Text = Yonghu.diqu;
            textBox_gerenxinxi_email.Text = Yonghu.email;
            textBox_gerenxinxi_jianjie.Text = Yonghu.jianjie;
            string[] shengri = Yonghu.shengri.Split('/');
            comboBox_gerenxinxi_shengri_nian.Text = shengri[0];
            comboBox_gerenxinxi_shengri_yue.Text = shengri[1];
            comboBox_gerenxinxi_shengri_ri.Text = shengri[2];
            //显示修改个人信息
            panel_gerenxinxi_xiugai.BringToFront();
        }

        private void comboBox_gerenxinxi_shengri_nian_SelectedIndexChanged(object sender, EventArgs e)
        {
            //个人信息 生日 日 下拉框绑定数据
            comboBox_gerenxinxi_shengri_ri.Items.Clear();
            int ri;
            if (comboBox_gerenxinxi_shengri_yue.Text == "1" || comboBox_gerenxinxi_shengri_yue.Text == "3" || comboBox_gerenxinxi_shengri_yue.Text == "5" || comboBox_gerenxinxi_shengri_yue.Text == "7" || comboBox_gerenxinxi_shengri_yue.Text == "8" || comboBox_gerenxinxi_shengri_yue.Text == "10" || comboBox_gerenxinxi_shengri_yue.Text == "12")
            {
                ri = 31;
            }
            else if (comboBox_gerenxinxi_shengri_yue.Text == "4" || comboBox_gerenxinxi_shengri_yue.Text == "6" || comboBox_gerenxinxi_shengri_yue.Text == "9" || comboBox_gerenxinxi_shengri_yue.Text == "11")
            {
                ri = 30;
            }
            else
            {
                if ((int.Parse(comboBox_gerenxinxi_shengri_nian.Text) % 4 == 0 && int.Parse(comboBox_gerenxinxi_shengri_nian.Text) % 100 != 0) || (int.Parse(comboBox_gerenxinxi_shengri_nian.Text) % 400 == 0))
                {
                    ri = 29;
                }
                else
                {
                    ri = 28;
                }
            }
            for (int i = 1; i <= ri; i++)
            {
                comboBox_gerenxinxi_shengri_ri.Items.Add(i);
            }
        }

        private void comboBox_gerenxinxi_shengri_yue_SelectedIndexChanged(object sender, EventArgs e)
        {
            //个人信息 生日 日 下拉框绑定数据
            comboBox_gerenxinxi_shengri_ri.Items.Clear();
            int ri;
            if (comboBox_gerenxinxi_shengri_yue.Text == "1" || comboBox_gerenxinxi_shengri_yue.Text == "3" || comboBox_gerenxinxi_shengri_yue.Text == "5" || comboBox_gerenxinxi_shengri_yue.Text == "7" || comboBox_gerenxinxi_shengri_yue.Text == "8" || comboBox_gerenxinxi_shengri_yue.Text == "10" || comboBox_gerenxinxi_shengri_yue.Text == "12")
            {
                ri = 31;
            }
            else if (comboBox_gerenxinxi_shengri_yue.Text == "4" || comboBox_gerenxinxi_shengri_yue.Text == "6" || comboBox_gerenxinxi_shengri_yue.Text == "9" || comboBox_gerenxinxi_shengri_yue.Text == "11")
            {
                ri = 30;
            }
            else
            {
                if ((int.Parse(comboBox_gerenxinxi_shengri_nian.Text) % 4 == 0 && int.Parse(comboBox_gerenxinxi_shengri_nian.Text) % 100 != 0) || (int.Parse(comboBox_gerenxinxi_shengri_nian.Text) % 400 == 0))
                {
                    ri = 29;
                }
                else
                {
                    ri = 28;
                }
            }
            for (int i = 1; i <= ri; i++)
            {
                comboBox_gerenxinxi_shengri_ri.Items.Add(i);
            }
        }

        private void button_gerenxinxi_xiugai_fanhui_Click(object sender, EventArgs e)
        {
            //返回
            panel_gerenxinxi_xiugai.SendToBack();
        }

        private void button_gerenxinxi_xiugai_baocun_Click(object sender, EventArgs e)
        {
            //保存修改信息
            string sql = string.Format("update Yonghu set Name='{0}',Xingbie=(select XingbieID from Xingbie where Xingbie='{1}'),Shengri='{2}',Diqu=(select DiquID from Diqu where Diqu='{3}'),Jianjie='{4}',Email='{5}' where Zhanghao='{6}'", textBox_gerenxinxi_name.Text, comboBox_gerenxinxi_xingbie.Text, comboBox_gerenxinxi_shengri_nian.Text + "-" + comboBox_gerenxinxi_shengri_yue.Text + "-" + comboBox_gerenxinxi_shengri_ri.Text, comboBox_gerenxinxi_diqu.Text, textBox_gerenxinxi_jianjie.Text, textBox_gerenxinxi_email.Text, Yonghu.zhanghao);
            DBHelper.ExecuteNonQuery(sql);
            //刷新数据
            sql = string.Format("select y.Name,x.Xingbie,y.Shengri,d.Diqu,y.Jianjie,y.Email from Yonghu y,Xingbie x,Diqu d where y.Xingbie=x.XingbieID and y.Diqu=d.DiquID and y.Zhanghao='{0}'", Yonghu.zhanghao);
            DataTable dt = DBHelper.GetDataTable(sql);
            Yonghu.name = dt.Rows[0]["Name"].ToString();
            Yonghu.xingbie = dt.Rows[0]["Xingbie"].ToString();
            Yonghu.shengri = dt.Rows[0]["Shengri"].ToString().Substring(0, dt.Rows[0]["Shengri"].ToString().IndexOf(' '));
            Yonghu.diqu = dt.Rows[0]["Diqu"].ToString();
            Yonghu.jianjie = dt.Rows[0]["Jianjie"].ToString();
            Yonghu.email = dt.Rows[0]["Email"].ToString();
            label_wodezhuye_nicheng.Text = Yonghu.name;
            label_wodezhuye_uid.Text = "UID:" + Yonghu.zhanghao + " | E-mail:" + Yonghu.email;
            label_wodezhuye_gerenxinxi.Text = Yonghu.xingbie + " | " + Yonghu.shengri + " | " + Yonghu.diqu;
            richTextBox_wodezhuye_jianjie.Text = Yonghu.jianjie;
            //返回
            panel_gerenxinxi_xiugai.SendToBack();
            MessageBox.Show("保存成功！");
        }

        private void button_wodeshuping_Click(object sender, EventArgs e)
        {
            try
            {
                string sql = string.Format("select s.ID,s.Neirong,b.bookName,s.Zhanghao,s.Time from Shuping s,Books b where s.bookID=b.bookID and Zhanghao='{0}'", Yonghu.zhanghao);
                DataTable dt = DBHelper.GetDataTable(sql);
                dataGridView_wodeshuping.DataSource = dt;
                dataGridView_wodeshuping.Columns["ID"].Visible = false;
                dataGridView_wodeshuping.Columns["Zhanghao"].Visible = false;
                label_wodeshuping_shuji.Text = dataGridView_wodeshuping.SelectedRows[0].Cells["shuji"].Value.ToString();
                label_wodeshuping_time.Text = dataGridView_wodeshuping.SelectedRows[0].Cells["shupingTime"].Value.ToString();
                label_wodeshuji_shuping.Text = dataGridView_wodeshuping.SelectedRows[0].Cells["shuping"].Value.ToString();
            }
            catch
            {
                label_wodeshuping_shuji.Text = "无评论";
                label_wodeshuping_time.Text = "";
                label_wodeshuji_shuping.Text = "您还没有评论过呢，先去参与评论吧！";
            }
            //显示我的书评
            panel_wodeshuping.BringToFront();
        }

        private void dataGridView_wodeshuping_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //填入数据
            label_wodeshuping_shuji.Text = dataGridView_wodeshuping.SelectedRows[0].Cells["shuji"].Value.ToString();
            label_wodeshuping_time.Text = dataGridView_wodeshuping.SelectedRows[0].Cells["shupingTime"].Value.ToString();
            label_wodeshuji_shuping.Text = dataGridView_wodeshuping.SelectedRows[0].Cells["shuping"].Value.ToString();
        }

        private void dataGridView_wodeshuping_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                //我的书评 右键操作 操作区域
                if (e.Button == MouseButtons.Right)
                {
                    if (e.RowIndex >= 0)
                    {
                        //右键操作 右键选定
                        dataGridView_wodeshuping.ClearSelection();
                        dataGridView_wodeshuping.Rows[e.RowIndex].Selected = true;
                        //右键操作 弹出菜单
                        contextMenuStrip_wodeshuping.Show(MousePosition.X, MousePosition.Y);
                    }
                }
            }
            catch
            {
                //右键操作 故障处理
                MessageBox.Show("右键操作出错，请检修！");
            }
        }

        private void 删除评论ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //删除评论
            try
            {
                string sql = string.Format("delete Shuping where ID='{0}'", dataGridView_wodeshuping.SelectedRows[0].Cells["ID"].Value.ToString());
                DBHelper.ExecuteNonQuery(sql);
                MessageBox.Show("成功删除！");
                //刷新数据
                sql = string.Format("select s.ID,s.Neirong,b.bookName,s.Zhanghao,s.Time from Shuping s,Books b where s.bookID=b.bookID and Zhanghao='{0}'", Yonghu.zhanghao);
                DataTable dt = DBHelper.GetDataTable(sql);
                dataGridView_wodeshuping.DataSource = dt;
                label_wodeshuping_shuji.Text = dataGridView_wodeshuping.SelectedRows[0].Cells["shuji"].Value.ToString();
                label_wodeshuping_time.Text = dataGridView_wodeshuping.SelectedRows[0].Cells["shupingTime"].Value.ToString();
                label_wodeshuji_shuping.Text = dataGridView_wodeshuping.SelectedRows[0].Cells["shuping"].Value.ToString();
            }
            catch
            {
                MessageBox.Show("删除失败！");
            }
        }

        private void button_wodeshuping_shuaxin_Click(object sender, EventArgs e)
        {
            //刷新数据
            string sql = string.Format("select s.ID,s.Neirong,b.bookName,s.Zhanghao,s.Time from Shuping s,Books b where s.bookID=b.bookID and Zhanghao='{0}'", Yonghu.zhanghao);
            DataTable dt = DBHelper.GetDataTable(sql);
            dataGridView_wodeshuping.DataSource = dt;
            label_wodeshuping_shuji.Text = dataGridView_wodeshuping.SelectedRows[0].Cells["shuji"].Value.ToString();
            label_wodeshuping_time.Text = dataGridView_wodeshuping.SelectedRows[0].Cells["shupingTime"].Value.ToString();
            label_wodeshuji_shuping.Text = dataGridView_wodeshuping.SelectedRows[0].Cells["shuping"].Value.ToString();
        }

        private void button_shezhi_Click(object sender, EventArgs e)
        {
            //显示设置页面
            panel_guanyu.BringToFront();
            panel_shezhi.BringToFront();
        }

        private void shezhi_guanyuchanping_Click(object sender, EventArgs e)
        {
            //显示关于产品
            panel_guanyu.BringToFront();
        }

        private void shezhi_xunqiubangzhu_Click(object sender, EventArgs e)
        {
            //显示寻求帮助
            panel_bangzhu.BringToFront();
        }

        private void shezhi_banbengenxin_Click(object sender, EventArgs e)
        {
            //显示版本更新
            panel_banbengenxin.BringToFront();
        }

        private void shezhi_fasongfankui_Click(object sender, EventArgs e)
        {
            //显示发送反馈
            panel_fasongfankui.BringToFront();
        }

        private void shezhi_xiugaimima_Click(object sender, EventArgs e)
        {
            //显示修改密码
            panel_xiugaimima.BringToFront();
        }

        private void button_xiugaimima_huoquyanzhengma_Click(object sender, EventArgs e)
        {
            if (shezhi_xiugaimima_email.Text == "")
            {
                MessageBox.Show("您还未输入电子邮箱地址！");
                return;
            }
            if (shezhi_xiugaimima_email.Text != Yonghu.email)
            {
                MessageBox.Show("这不是您绑定的电子邮件地址！");
                return;
            }
            //修改密码 获取验证码
            Yanzhengma.yanzhengma = Email.email(shezhi_xiugaimima_email.Text);
        }

        private void button_xiugaimima_Click(object sender, EventArgs e)
        {
            //修改密码 验证
            if (shezhi_xiugaimima_mima.Text == "" || shezhi_xiugaimima_querenmima.Text == "")
            {
                MessageBox.Show("您还未输入密码！");
                return;
            }
            if (shezhi_xiugaimima_email.Text == "")
            {
                MessageBox.Show("您还未输入电子邮箱地址！");
                return;
            }
            if (shezhi_xiugaimima_yanzhengma.Text == "")
            {
                MessageBox.Show("您还未输入验证码！");
                return;
            }
            if (shezhi_xiugaimima_yanzhengma.Text != Yanzhengma.yanzhengma)
            {
                MessageBox.Show("您输入的验证码不正确！");
                shezhi_xiugaimima_yanzhengma.Text = "";
                return;
            }
            //修改密码
            string sql = string.Format("update Yonghu set Mima='{0}' where Zhanghao='{1}'", shezhi_xiugaimima_mima.Text, Yonghu.zhanghao);
            if (DBHelper.ExecuteNonQuery(sql))
            {
                Yonghu.mima = shezhi_xiugaimima_mima.Text;
                MessageBox.Show("密码修改成功！");
                shezhi_xiugaimima_mima.Text = "";
                shezhi_xiugaimima_querenmima.Text = "";
                shezhi_xiugaimima_email.Text = "";
                shezhi_xiugaimima_yanzhengma.Text = "";
            }
        }

        private void button_qingkongfankui_Click(object sender, EventArgs e)
        {
            //清空反馈
            textBox_fankuineirong.Text = "";
        }

        private void button_fasongfankui_Click(object sender, EventArgs e)
        {
            //发送反馈
            string sql = string.Format("insert Fankui (Zhanghao,Neirong) select '{0}','{1}'", Yonghu.zhanghao, textBox_fankuineirong.Text);
            if (DBHelper.ExecuteNonQuery(sql))
            {
                MessageBox.Show("反馈成功！");
            }
        }

        private void button_chengweizuozhe_Click(object sender, EventArgs e)
        {
            Main main = new Main(Yonghu.name, "作者");
            main.ShowDialog();
        }

        private void button_qingkongpinglun_Click(object sender, EventArgs e)
        {
            //清空评论
            textBox_pinglun.Text = "";
        }

        private void button_tijiaopinglin_Click(object sender, EventArgs e)
        {
            try
            {
                //提交评论
                string sql = string.Format("insert Shuping (Neirong,bookID,Zhanghao) select '{0}','{1}','{2}'", textBox_pinglun.Text, DGV_shujiguanli_sousuo.SelectedRows[0].Cells["bookID"].Value.ToString(), Yonghu.zhanghao);
                DBHelper.ExecuteNonQuery(sql);
                textBox_pinglun.Text = "";
                panel_shujixinxi.BringToFront();
            }
            catch
            {
                MessageBox.Show("评论失败！");
            }
        }

        private void button_shujixinxi_pinglun_Click(object sender, EventArgs e)
        {
            //显示评论页面
            textBox_pinglun.Text = "";
            panel_pinglun.BringToFront();
        }
    }
}
